C#绘制三角形并填充,使用winform实现qq聊天气泡

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

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

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

效果:

C#绘制三角形并填充,使用winform实现qq聊天气泡

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

C#绘制三角形并填充,使用winform实现qq聊天气泡

Winform仿制QQ微信聊天窗口气泡

绘制圆角矩形的代码:

//窗口圆角
private void Main_Paint(object sender, PaintEventArgs e)
{
List<Point> list = new List<Point>();
int width = this.Width;
int height = this.Height; #region 四个圆角 //左上
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, ));
list.Add(new Point(, )); //右上
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , ));
list.Add(new Point(width - , )); //右下
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - ));
list.Add(new Point(width - , height - )); //左下
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - ));
list.Add(new Point(, height - )); #endregion Point[] points = list.ToArray(); GraphicsPath shape = new GraphicsPath();
shape.AddPolygon(points); this.Region = new System.Drawing.Region(shape); }
上一篇:[15]Windows内核情景分析 --- 权限管理


下一篇:模仿QQ空间 网页设计