码迷,mamicode.com
首页 > Windows程序 > 详细

C# 画圆角矩形

时间:2014-11-26 18:35:27      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:io   ar   color   os   sp   on   bs   ad   as   

            int width = panel2.Width;
            int height = panel2.Height;
            int lineWeight = 10;//边框宽
            int radio = 30;//圆周半径
            Graphics g = panel2.CreateGraphics();
            //panel1.BackColor = System.Drawing.Color.Transparent;
            Bitmap bm = new Bitmap(width, width);
            Graphics grs = Graphics.FromImage(bm);
            grs.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            grs.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            grs.Clear(Color.White);
            int padding = 15;//向内缩进
            //左上圆角
            grs.FillPie(Brushes.LightSalmon, padding, padding, radio * 2, radio * 2, 180, 90);
            //左下
            grs.FillPie(Brushes.LightSalmon, padding, height - 2 * radio - padding, radio * 2, radio * 2, 90, 90);
            //右上
            grs.FillPie(Brushes.LightSalmon, width - 2 * radio - padding, padding, radio * 2, radio * 2, 270, 90);
            //右下
            grs.FillPie(Brushes.LightSalmon, width - 2 * radio - padding, height - 2 * radio - padding, radio * 2, radio * 2, 0, 90);

            //竖向矩形
            grs.FillRectangle(Brushes.LightSalmon, radio + padding - 1, padding, width - 2 * radio - 2 * padding + 2, height - 2 * padding);
            //横向矩形
            grs.FillRectangle(Brushes.LightSalmon, padding, radio - 1 + padding, width - 2 * padding, height - 2 * radio - 2 * padding + 2);

            if (lineWeight > 0)
            {
                Pen p = new Pen(Brushes.Blue, lineWeight);
                //左上弧
                grs.DrawArc(p, padding, padding, radio * 2, radio * 2, 180, 90);
                //左下
                grs.DrawArc(p, padding, height - 2 * radio - padding, radio * 2, radio * 2, 90, 90);
                //右上
                grs.DrawArc(p, width - 2 * radio - padding, padding, radio * 2, radio * 2, 270, 90);
                //右下
                grs.DrawArc(p, width - 2 * radio - padding, height - 2 * radio - padding, radio * 2, radio * 2, 0, 90);

                //上框
                grs.DrawLine(p, radio + padding - 1, padding, width - radio - padding + 2, padding);
                //下
                grs.DrawLine(p, radio + padding - 1, height - padding, width - radio - padding + 2, height - padding);
                //左
                grs.DrawLine(p, padding, radio + padding - 1, padding, height - radio - padding + 2);
                //右
                grs.DrawLine(p, width - padding, radio + padding - 1, width - padding, height - radio - padding + 2);
            }


            g.DrawImage(bm, 0, 0);
            grs.Dispose();
            bm.Dispose();
            g.Dispose();

C# 画圆角矩形

标签:io   ar   color   os   sp   on   bs   ad   as   

原文地址:http://www.cnblogs.com/biyyss_sun/p/4123838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!