加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 禁用winform按钮上的悬停行为

发布时间:2020-12-15 19:57:25 所属栏目:百科 来源:网络整理
导读:我正在使用C#4.0开发一个winform应用程序 我有一个带一个按钮的表格.我将按钮的BackColor更改为黄色.在运行时,当我将鼠标移到它上面时,按钮的背面颜色会稍微改变.我想禁用它.无论发生什么,我希望颜色保持不变. 这是表单代码: using System;using System.Win
我正在使用C#4.0开发一个winform应用程序

我有一个带一个按钮的表格.我将按钮的BackColor更改为黄色.在运行时,当我将鼠标移到它上面时,按钮的背面颜色会稍微改变.我想禁用它.无论发生什么,我希望颜色保持不变.

这是表单代码:

using System;
using System.Windows.Forms;

namespace Something
{
    public partial class Home : Form
    {
        public Home()
        {
            InitializeComponent();
        }

    }
}



namespace Something
{
partial class Home
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise,false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Home));
        this.button1 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.BackColor = System.Drawing.Color.Yellow;
        resources.ApplyResources(this.button1,"button1");
        this.button1.Name = "button1";
        this.button1.UseVisualStyleBackColor = false;
        // 
        // Home
        // 
        resources.ApplyResources(this,"$this");
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(226)))),((int)(((byte)(227)))),((int)(((byte)(228)))));
        this.Controls.Add(this.button1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.Name = "Home";
        this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        this.Load += new System.EventHandler(this.Home_Load);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.Button button1;



}
}

提前致谢.

解决方法

如果你已经将FlatStyle设置为flat,那么你可以做这样的事情很简单:

//place this code in your form constructor
button1.FlatAppearance.MouSEOverBackColor = button1.BackColor;
button1.BackColorChanged += (s,e) => {
   button1.FlatAppearance.MouSEOverBackColor = button1.BackColor;
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读