[英]How can i draw a rectangle in a picture box or in a panel?
我有一个带有 PictureBox(或面板)的窗体,我想在此 PictureBox 的点 (0,0) 中绘制一个矩形。 我能怎么做??
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void DrawIt()
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(50, 50, 150, 150);
SolidBrush brush = new SolidBrush(Color.Red);
graphics.DrawRectangle(System.Drawing.Pens.Red, rectangle);
graphics.FillRectangle(brush, rectangle);
}
private void button1_Click(object sender, EventArgs e)
{
this.DrawIt();
}
}`
private void button1_Click(object sender, EventArgs e)
{
SolidBrush brush = new SolidBrush(Color.Red);
Pen pen = new Pen(Color.Red);
Rectangle rectangle = new Rectangle(50, 50, 150, 150);
pictureBox1.CreateGraphics().DrawReactangle(pen, rectangle);
pictureBox1.CreateGraphics().FillRectangle(brush, rectangle);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.