如何在图片框或面板中绘制矩形?

时间:2019-03-13 16:35:27

标签: c#

我有一个带有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();
            }
        }`

0 个答案:

没有答案