winform控件在Enable=false的情况下改变它的字体颜色

Posted 寒夜美美

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了winform控件在Enable=false的情况下改变它的字体颜色相关的知识,希望对你有一定的参考价值。

[System.Runtime.InteropServices.DllImport("user32.dll ")]

        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc);
        [System.Runtime.InteropServices.DllImport("user32.dll ")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
 
        public const int GWL_STYLE = -16;
        public const int WS_DISABLED = 0x8000000;
 
        public static void SetControlEnabled(Control c, bool enabled)
        {
            if (enabled)
            { SetWindowLong(c.Handle, GWL_STYLE, (~WS_DISABLED) & GetWindowLong(c.Handle, GWL_STYLE)); }
            else
            { SetWindowLong(c.Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(c.Handle, GWL_STYLE)); }
        }
 
        private void button2_Click(object sender, System.EventArgs e)
        {
            SetControlEnabled(this.button1, false);
            this.button1.ForeColor = Color.White;
        }

以上是关于winform控件在Enable=false的情况下改变它的字体颜色的主要内容,如果未能解决你的问题,请参考以下文章