簡體   English   中英

如何在圖片框或面板中繪制矩形?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM