博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#绘制三角形并填充,使用winform实现qq聊天气泡
阅读量:6840 次
发布时间:2019-06-26

本文共 7491 字,大约阅读时间需要 24 分钟。

首先是需求,需要制作一个聊天气泡, 但是winform中有没有类似Android的.9图,只有自己设计图形拼接气泡。

第一种是绘制空心三角形,第二种是绘制三角形区域,可以指定RGB颜色。

private void Form1_Paint(object sender, PaintEventArgs e)        {            Pen pen = new Pen(Color.Red, 1);                        e.Graphics.DrawLine(pen, 10, 10, 50, 10);            e.Graphics.DrawLine(pen, 10, 10, 50, 50);            e.Graphics.DrawLine(pen, 50, 10, 50, 50);            Color color = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(54)))), ((int)(((byte)(82)))));            Brush brushes = new SolidBrush(color);            Point[] point new Point[3];            point[0] = new Point(50,100);            point[1] = new Point(100,50);            point[2] = new Point(100,100);            e.Graphics.FillPolygon(brushes, point);        }

 效果:

可以作为气泡中的箭头,另外四个角用椭圆:

 

 

绘制圆角矩形的代码:

//窗口圆角   private void Main_Paint(object sender, PaintEventArgs e)        {            List
list = new List
(); int width = this.Width; int height = this.Height; #region 四个圆角 //左上 list.Add(new Point(0, 47)); list.Add(new Point(1, 42)); list.Add(new Point(2, 38)); list.Add(new Point(3, 36)); list.Add(new Point(4, 33)); list.Add(new Point(5, 32)); list.Add(new Point(6, 29)); list.Add(new Point(7, 27)); list.Add(new Point(8, 26)); list.Add(new Point(9, 24)); list.Add(new Point(10, 22)); list.Add(new Point(11, 21)); list.Add(new Point(12, 20)); list.Add(new Point(13, 19)); list.Add(new Point(14, 17)); list.Add(new Point(15, 16)); list.Add(new Point(16, 15)); list.Add(new Point(17, 14)); list.Add(new Point(19, 13)); list.Add(new Point(20, 12)); list.Add(new Point(21, 11)); list.Add(new Point(22, 10)); list.Add(new Point(24, 9)); list.Add(new Point(26, 8)); list.Add(new Point(27, 7)); list.Add(new Point(29, 6)); list.Add(new Point(32, 5)); list.Add(new Point(33, 4)); list.Add(new Point(36, 3)); list.Add(new Point(38, 2)); list.Add(new Point(42, 1)); list.Add(new Point(47, 0)); //右上 list.Add(new Point(width - 47, 0)); list.Add(new Point(width - 42, 1)); list.Add(new Point(width - 38, 2)); list.Add(new Point(width - 36, 3)); list.Add(new Point(width - 33, 4)); list.Add(new Point(width - 32, 5)); list.Add(new Point(width - 29, 6)); list.Add(new Point(width - 27, 7)); list.Add(new Point(width - 26, 8)); list.Add(new Point(width - 24, 9)); list.Add(new Point(width - 22, 10)); list.Add(new Point(width - 21, 11)); list.Add(new Point(width - 20, 12)); list.Add(new Point(width - 19, 13)); list.Add(new Point(width - 17, 14)); list.Add(new Point(width - 16, 15)); list.Add(new Point(width - 15, 16)); list.Add(new Point(width - 14, 17)); list.Add(new Point(width - 13, 19)); list.Add(new Point(width - 12, 20)); list.Add(new Point(width - 11, 21)); list.Add(new Point(width - 10, 22)); list.Add(new Point(width - 9, 24)); list.Add(new Point(width - 8, 26)); list.Add(new Point(width - 7, 27)); list.Add(new Point(width - 6, 29)); list.Add(new Point(width - 5, 32)); list.Add(new Point(width - 4, 33)); list.Add(new Point(width - 3, 36)); list.Add(new Point(width - 2, 38)); list.Add(new Point(width - 1, 42)); list.Add(new Point(width - 0, 47)); //右下 list.Add(new Point(width - 0, height - 47)); list.Add(new Point(width - 1, height - 42)); list.Add(new Point(width - 2, height - 38)); list.Add(new Point(width - 3, height - 36)); list.Add(new Point(width - 4, height - 33)); list.Add(new Point(width - 5, height - 32)); list.Add(new Point(width - 6, height - 29)); list.Add(new Point(width - 7, height - 27)); list.Add(new Point(width - 8, height - 26)); list.Add(new Point(width - 9, height - 24)); list.Add(new Point(width - 10, height - 22)); list.Add(new Point(width - 11, height - 21)); list.Add(new Point(width - 12, height - 20)); list.Add(new Point(width - 13, height - 19)); list.Add(new Point(width - 14, height - 17)); list.Add(new Point(width - 15, height - 16)); list.Add(new Point(width - 16, height - 15)); list.Add(new Point(width - 17, height - 14)); list.Add(new Point(width - 19, height - 13)); list.Add(new Point(width - 20, height - 12)); list.Add(new Point(width - 21, height - 11)); list.Add(new Point(width - 22, height - 10)); list.Add(new Point(width - 24, height - 9)); list.Add(new Point(width - 26, height - 8)); list.Add(new Point(width - 27, height - 7)); list.Add(new Point(width - 29, height - 6)); list.Add(new Point(width - 32, height - 5)); list.Add(new Point(width - 33, height - 4)); list.Add(new Point(width - 36, height - 3)); list.Add(new Point(width - 38, height - 2)); list.Add(new Point(width - 42, height - 1)); list.Add(new Point(width - 47, height - 0)); //左下 list.Add(new Point(47, height - 0)); list.Add(new Point(42, height - 1)); list.Add(new Point(38, height - 2)); list.Add(new Point(36, height - 3)); list.Add(new Point(33, height - 4)); list.Add(new Point(32, height - 5)); list.Add(new Point(29, height - 6)); list.Add(new Point(27, height - 7)); list.Add(new Point(26, height - 8)); list.Add(new Point(24, height - 9)); list.Add(new Point(22, height - 10)); list.Add(new Point(21, height - 11)); list.Add(new Point(20, height - 12)); list.Add(new Point(19, height - 13)); list.Add(new Point(17, height - 14)); list.Add(new Point(16, height - 15)); list.Add(new Point(15, height - 16)); list.Add(new Point(14, height - 17)); list.Add(new Point(13, height - 19)); list.Add(new Point(12, height - 20)); list.Add(new Point(11, height - 21)); list.Add(new Point(10, height - 22)); list.Add(new Point(9, height - 24)); list.Add(new Point(8, height - 26)); list.Add(new Point(7, height - 27)); list.Add(new Point(6, height - 29)); list.Add(new Point(5, height - 32)); list.Add(new Point(4, height - 33)); list.Add(new Point(3, height - 36)); list.Add(new Point(2, height - 38)); list.Add(new Point(1, height - 42)); list.Add(new Point(0, height - 47)); #endregion Point[] points = list.ToArray(); GraphicsPath shape = new GraphicsPath(); shape.AddPolygon(points); this.Region = new System.Drawing.Region(shape); }
View Code

 

转载地址:http://pgbul.baihongyu.com/

你可能感兴趣的文章
《C语言程序设计与实践(第2版)》——导读
查看>>
《计算机科学概论(第12版)》—第1章1.4节用位模式表示信息
查看>>
C2B前还有S2b,阿里携手产学研探索新零售时代的供应链未来
查看>>
Linux集群和自动化维2.4.2 sed的用法示例
查看>>
《OpenGL ES 3.x游戏开发(上卷)》一1.2 搭建Android开发环境
查看>>
《HTML5实战》——2.6 小结
查看>>
使用 Python 和 Asyncio 编写在线多人游戏(三)
查看>>
yanf4j 1.0-stable的一个压测报告
查看>>
Square 技术团队的开源其 Vim 配置文件
查看>>
《Java编码指南:编写安全可靠程序的75条建议》—— 指南6:正确地编码或转义输出...
查看>>
阿里NASA的液冷黑科技 | 彻底激活未来AI大脑超能力
查看>>
stack源码分析
查看>>
Java内存溢出(OOM)异常完全指南
查看>>
云计算十字真言及其在小博无线的实践
查看>>
用一生回味的经典语录
查看>>
你的命运不是一头骡子
查看>>
排序算法之鸽巢排序
查看>>
Appium移动自动化框架
查看>>
无线动态化解决方案总结:从WeApp到Weex
查看>>
CentOS上安装Bugzilla 4.5.2
查看>>