×

重绘ComboBox控件,为什么文本框中下面有条粗黑线

Kalet Kalet 发表于2009-03-20 12:00:14 浏览181 评论0

抢沙发发表评论



重绘ComboBox控件,为什么文本框中下面有条粗黑线










重绘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);     //释放重绘ComboBox控件,为什么文本框中下面有条粗黑线
        }
    }
}

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






 回复内容
【xwk789xwk】:
不是很懂,帮你顶一下

【bigeyescat】:
帮顶

【zswang】:
这句话屏蔽掉看看
//m.Result = IntPtr.Zero;     //返回结果

【ycqing】:
mark

【bigeyescat】:
if (m.Msg == 0xf || m.Msg == 0x133)     //拦截系统消息
这句改成 if (m.Msg == 0xf)  试试


【BIGBOLL_LSLSLSL】:重绘ComboBox控件,为什么文本框中下面有条粗黑线
zswang(伴水清清) 和 bigeyescat(大眼猫)的方法都可以,结帐


群贤毕至

访客