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();

posted @ 2015-11-27 10:38  燕儿归  阅读(2519)  评论(0编辑  收藏  举报