0
我想在窗體上的PictureBox上畫一個矩形。如何在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);
}
}
我在想什麼?
哇!我怎麼沒有注意到這一點。謝謝。 – etoisarobot 2010-03-19 21:16:01