c# - C# : How to remove hover background? 中的自定义按钮

标签 c# .net winforms button

我正在尝试使用 Visual Studio 2005 为我的表单(具有 FormBorderStyle = none)创建一个自定义按钮。我在链接到该按钮的 ImageList 中有我的 3 种状态按钮图像。

this.btnClose.AutoSize = false;
this.btnClose.BackColor = System.Drawing.Color.Transparent;
this.btnClose.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.btnClose.FlatAppearance.BorderSize = 0;
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnClose.ForeColor = System.Drawing.Color.Transparent;
this.btnClose.ImageKey = "Disabled";
this.btnClose.ImageList = this.imageList1;
this.btnClose.Location = new System.Drawing.Point(368, -5);
this.btnClose.Margin = new System.Windows.Forms.Padding(0);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(31, 31);
this.btnClose.TabIndex = 0;
this.btnClose.UseVisualStyleBackColor = false;
this.btnClose.MouseLeave += new System.EventHandler(this.btnClose_MouseLeave);
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
this.btnClose.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnClose_MouseDown);
this.btnClose.MouseHover += new System.EventHandler(this.btnClose_MouseHover);

private void btnClose_MouseHover(object sender, EventArgs e)
{
    btnClose.ImageKey = "enabled";
}

private void btnClose_MouseDown(object sender, MouseEventArgs e)
{
    btnClose.ImageKey = "down";
}

private void btnClose_MouseLeave(object sender, EventArgs e)
{
    btnClose.ImageKey = "disabled";
}

一切正常,但有一个问题。每当我将鼠标悬停在按钮上时,我都会得到一个非常烦人的灰色背景。

我怎样才能删除它?

最佳答案

btnClose.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;

关于c# - C# : How to remove hover background? 中的自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/195114/

相关文章:

.net - 刷新服务引用更新 app.config

c# - C# Windows 窗体鼠标事件问题中的自定义控件

c# - 如何使用长处理步骤将事件添加到 C# Windows 应用程序

c# - 将 IList<string> 转换为 List<string>()

c# - 从模拟方法返回模拟

.net - 多线程单元测试

c# - 使用线程安全的 .NET 4+ 集合时是否可能导致死锁?

c# - CB_SELECTSTRING 不适用于日文项目

c# - 如何以秒为单位创建时间戳

c# - 防止窗口跨越多个显示器