c# - 按钮 WinForms 的 70% 不透明度颜色

标签 c# winforms

我想在我将鼠标悬停在按钮上时仍然保持 30% 透明(这样您可以从表单中看到背景图像)但仍然看到一些颜色时产生这种效果..

我试过了,但这只是给我一片空白:

private void roundedButton2_MouseEnter(object sender, EventArgs e)
        {
            roundedButton2.UseVisualStyleBackColor = false;
            roundedButton2.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, Color.Black);
        }

        private void roundedButton2_MouseLeave(object sender, EventArgs e)
        {
            roundedButton2.UseVisualStyleBackColor = true;
            roundedButton2.BackColor = Color.Transparent;
        }

在这里,我将鼠标移出并将鼠标放在按钮上,这样您就可以看到我拥有的东西。 编辑:解决了....现在上面的代码完全符合我的要求。

最佳答案

问题解决了。我将代码更改如下:

private void roundedButton2_MouseEnter(object sender, EventArgs e)
        {
            roundedButton2.UseVisualStyleBackColor = false;
            roundedButton2.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, Color.Black);
        }

        private void roundedButton2_MouseLeave(object sender, EventArgs e)
        {
            roundedButton2.UseVisualStyleBackColor = true;
            roundedButton2.BackColor = Color.Transparent;
        }

必须在背景色之前添加 FlatAppearance

关于c# - 按钮 WinForms 的 70% 不透明度颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41203825/

相关文章:

c# - 前缀 DTO/POCOS - 命名约定?

c# - 用于有序集合的正确集合

c# - 当 T 是结构时,List<T>.Find 如何工作?

c# - 将表单名称转换为c#.net中的表单对象

c# - 如何将组添加到 ListView,然后将项目添加到组

c# - 在静态字段中引用自身的类可以被垃圾收集吗?

javascript - 从 HttpPost Asp.Net MVC 方法返回用于保存的文件

c# - 有没有快速的方法来获得鼠标下的控件?

c# - 如何允许用户移动窗体上的控件

c# - 在另一个窗口之上叠加一个顶层窗口