![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
C#如何去掉ComboBox的下拉按钮
在C#论坛看到有人问,如何让ComboBox下拉按钮只在获取焦点时显示,在那个论坛无法登陆,在这里做下回答protectedoverridevoidWndProc(ref...
在C#论坛看到有人问,如何让ComboBox下拉按钮只在获取焦点时显示,在那个论坛无法登陆,在这里做下回答
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_PAINT)
{ Graphics graphics = Graphics.FromHwnd(this.Handle);
PaintEventArgs pe = new PaintEventArgs(graphics, new Rectangle(0, 0, this.Width, this.Height));
OnPaint(pe); }
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
this.Invalidate();
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (!this.Focused)
{
Brush bB = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(bB, new Rectangle(base.Width - base.Height+1, 1, base.Height-2, base.Height-2));
bB.Dispose();
}
}
重写ComboBox上述方法 展开
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_PAINT)
{ Graphics graphics = Graphics.FromHwnd(this.Handle);
PaintEventArgs pe = new PaintEventArgs(graphics, new Rectangle(0, 0, this.Width, this.Height));
OnPaint(pe); }
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
this.Invalidate();
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (!this.Focused)
{
Brush bB = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(bB, new Rectangle(base.Width - base.Height+1, 1, base.Height-2, base.Height-2));
bB.Dispose();
}
}
重写ComboBox上述方法 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
2009-10-23
展开全部
简单来说就是重画按钮区域
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询