日期:2014-05-19  浏览次数:21014 次

重绘ComboBox控件,为什么文本框中下面有条粗黑线
如题,代码如下
public   partial   class   myComboBox   :   System.Windows.Forms.ComboBox
{
        [System.Runtime.InteropServices.DllImport( "user32.dll ")]
        static   extern   IntPtr   GetWindowDC(IntPtr   hWnd);
        [System.Runtime.InteropServices.DllImport( "user32.dll ")]
        static   extern   int   ReleaseDC(IntPtr   hWnd,   IntPtr   hDC);

        public   myComboBox()   :   base()
        {
                this.FlatStyle   =   FlatStyle.Flat;
        }

        protected   override   void   WndProc(ref   Message   m)
        {
                base.WndProc(ref   m);
                if   (m.Msg   ==   0xf   ||   m.Msg   ==   0x133)           //拦截系统消息
                {
                        IntPtr   hDC   =   GetWindowDC(m.HWnd);
                        if   (hDC.ToInt32()   ==   0)
                        {   return;   }

                        Graphics   g   =   Graphics.FromHdc(hDC);

                        //边框
                        Rectangle   rect   =   new   Rectangle(0,   0,   Width,   Height);
                        ControlPaint.DrawBorder(g,   rect,   Color.DarkGray,   ButtonBorderStyle.Solid);

                        m.Result   =   IntPtr.Zero;           //返回结果
                        ReleaseDC(m.HWnd,   hDC);           //释放
                }
        }
}

运行时在Win2000没问题,在XP下ComboBox控件文本框里有条粗黑线,在主窗体中   Main()方法把Application.EnableVisualStyles();这句注释掉就好了。
我现在不想注释这句,在XP样式下怎样能去掉这条黑线,求教各位高手。

------解决方案--------------------
这句话屏蔽掉看看
//m.Result = IntPtr.Zero; //返回结果
------解决方案--------------------
if (m.Msg == 0xf || m.Msg == 0x133) //拦截系统消息
这句改成 if (m.Msg == 0xf) 试试