【发布时间】:2012-08-05 10:18:13
【问题描述】:
以下问题需要您的帮助(使用 .Net 3.5 和 Windows 窗体):
我只是想在位于窗体上的组合框(Windows 窗体)的中间画一条线。
我使用的代码是:
void comboBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(Brushes.DarkBlue),
this.comboBox1.Location.X,
this.comboBox1.Location.Y + (this.comboBox1.Size.Height / 2),
this.comboBox1.Location.X + this.comboBox1.Size.Width,
this.comboBox1.Location.Y + (this.comboBox1.Size.Height / 2));
}
触发绘制事件:
private void button1_Click(object sender, EventArgs e)
{
comboBox1.Refresh();
}
当我执行代码并按下按钮时,线条不会被绘制。在调试中,绘制处理程序处的断点没有被命中。奇怪的是在MSDN ComBox 的事件列表中有一个绘制事件,但是在 VS 2010 中,IntelliSense 在 ComboBox 的成员中没有找到这样的事件
谢谢。
【问题讨论】:
-
我认为你必须重写组合框的 OnPaint 事件并触发绘画,你可以调用 InvalidateRect
标签: c# winforms combobox system.drawing