【发布时间】:2010-03-20 05:11:04
【问题描述】:
我正在尝试在窗体上的 PictureBox 上绘制一个矩形。
如here 所示编写文本可以正常工作。
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
using (Font myFont = new Font("Arial", 14))
{
e.Graphics.DrawString("Hello .NET Guide!", myFont, Brushes.Green, new Point(2, 2));
}
}
但是当我尝试像这样绘制一个矩形时,什么都没有出现。
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle();
rect.Location = new Point(25, 25);
rect.Width = 50;
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rect);
}
}
我错过了什么?
【问题讨论】: