前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C#GDI画立体渐变圆角panel

C#GDI画立体渐变圆角panel

作者头像
恋喵大鲤鱼
发布2018-08-03 17:27:18
6690
发布2018-08-03 17:27:18
举报
文章被收录于专栏:C/C++基础

为要处理的panel添加绘画事件,代码写在panel的Paint事件中:

 private void panel1_Paint(object sender, PaintEventArgs e)         {

            //(new 一个矩形,范围为panel的上半部分)

            Rectangle rt1 = new Rectangle(0, 0, panel1.Width, (panel1.Height/2));

            //(new一个渐变笔刷,渐变范围为上面新建的矩形,即panel的上半部分,渐变色从白色到蓝色,渐变角度LinearGradientMode.Vertical为垂直渐变)             LinearGradientBrush br = new LinearGradientBrush(rt1, Color.White, Color.Blue,   LinearGradientMode.Vertical);             Graphics g = e.Graphics;//为控件创建Graphics             g.FillRectangle(br, rt1);//填充矩形

//(下面同上面的操作,渐变panel的下半部分)             LinearGradientBrush br2 = new LinearGradientBrush(rt1, Color.Blue, Color.White, LinearGradientMode.Vertical);             Rectangle rt2 = new Rectangle(0,(panel1.Height/2), panel1.Width, panel1.Height/2);             g.FillRectangle(br2, rt2);

            //实现圆角形状的panel             List list = new List();//建立点集合list             int width = this.panel1.Width;             int height = this.panel1.Height;             //panel左上的点             list.Add(new Point(0, 4));             list.Add(new Point(1, 4));             list.Add(new Point(1, 3));             list.Add(new Point(2, 2));             list.Add(new Point(3, 1));             list.Add(new Point(4, 1));             list.Add(new Point(4, 0));             //panel右上的点             list.Add(new Point(width - 4, 0));             list.Add(new Point(width - 4, 1));             list.Add(new Point(width - 3, 1));             list.Add(new Point(width - 2, 2));             list.Add(new Point(width - 1, 3));             list.Add(new Point(width - 1, 4));             list.Add(new Point(width - 0, 4));             //panel右下角的点             list.Add(new Point(width - 0, height - 4));

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015年07月19日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档