c# winfrom 在panel上绘制矩形


Bitmap b = new Bitmap(panel1.Width, panel1.Height);
            Graphics g = Graphics.FromImage(b);
            Rectangle rect = new Rectangle((panel1.Width / 2) - 128, (panel1.Height / 2) - 152, 256, 304);
            g.DrawRectangle(new Pen(Color.Lime, 2), rect);
            g.Dispose();
            panel1.BackgroundImage = b;

也可以这么用

Graphics g = panel1.CreateGraphics();

转载于:https://www.cnblogs.com/yanergui/p/5014279.html

你可能感兴趣的:(c# winfrom 在panel上绘制矩形)