高手来看看,碰到个难题,如何重绘ComboBox的输入框部分

lovelan1748 2009-11-29 01:47:17
OnPaint没有效果。
Combobox的FlatStyle为Flat,外围的边框还好说,输入框与下拉按钮中间的竖线应该怎么绘制呢
如下图红线

...全文
448 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovelan1748 2009-11-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 starts_2000 的回复:]
引用 8 楼 lovelan1748 的回复:
引用 7 楼 starts_2000 的回复:
参考

你没明白我要干啥

整个我都可以重绘,还不知道你要干啥,你看懂了,想怎么画就怎么画
[/Quote]
是,我急了点,想快点解决,没仔细读,谢了
starts_2000 2009-11-29
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lovelan1748 的回复:]
引用 7 楼 starts_2000 的回复:
参考

你没明白我要干啥
[/Quote]
整个我都可以重绘,还不知道你要干啥,你看懂了,想怎么画就怎么画
Sugar_Tiger 2009-11-29
  • 打赏
  • 举报
回复
加一句就行

g.DrawLine(new Pen(Brushes.Blue, 2), new PointF(this.Width - this.Height, 0), new PointF(this.Width - this.Height, this.Height));


[Quote=引用 5 楼 lovelan1748 的回复:]
ControlPaint.DrawBorder是画边框,请问能只画Line吗?ControlPaint里面好像没这个方法,比如我只想画上下边框,而左右不需要的画,DrawBorder就办不到了
[/Quote]
lovelan1748 2009-11-29
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ajaxtop 的回复:]
学习一下,为了个边框要搞这么多东东啊
[/Quote]
因为ComboBox是系统进程进行绘制的,重写OnPaint无效,所以只能对消息处理了
lovelan1748 2009-11-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 starts_2000 的回复:]
参考
[/Quote]
你没明白我要干啥
starts_2000 2009-11-29
  • 打赏
  • 举报
回复
ajaxtop 2009-11-29
  • 打赏
  • 举报
回复
学习一下,为了个边框要搞这么多东东啊
lovelan1748 2009-11-29
  • 打赏
  • 举报
回复
ControlPaint.DrawBorder是画边框,请问能只画Line吗?ControlPaint里面好像没这个方法,比如我只想画上下边框,而左右不需要的画,DrawBorder就办不到了
lovelan1748 2009-11-29
  • 打赏
  • 举报
回复
谢楼上,我试试
Sugar_Tiger 2009-11-29
  • 打赏
  • 举报
回复
解决了,呵呵,


[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);

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);
//画坚经
Rectangle rect1 = new Rectangle(Width - Height, 0, Height, Height);
ControlPaint.DrawBorder(g, rect, Color.Red, ButtonBorderStyle.Solid);
ControlPaint.DrawBorder(g, rect1, Color.Red, ButtonBorderStyle.Solid);
ReleaseDC(m.HWnd, hDC);
}
}


注:参考了http://topic.csdn.net/u/20070728/01/7e5ebf43-fce8-4db1-a05c-d44c612d1391.html
lovelan1748 2009-11-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sugar_tiger 的回复:]
再加一句
e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new PointF(this.Width - this.Height, 0), new PointF(this.Width -this.Height, this.Height));

[/Quote]
这样不行的,你可以试一下实际上重写OnPaint并没有效果
Sugar_Tiger 2009-11-29
  • 打赏
  • 举报
回复
再加一句
e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new PointF(this.Width - this.Height, 0), new PointF(this.Width -this.Height, this.Height));

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧