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;
         }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM