zoukankan      html  css  js  c++  java
  • C#绘制三角形并填充,使用winform实现qq聊天气泡

    首先是需求,需要制作一个聊天气泡, 但是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);
            }

     效果:

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

     

    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(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
  • 相关阅读:
    Ajax请求ashx 返回 json 格式数据常见问题
    netbeans 优化设置
    Java基础static的探究
    mybatis中:selectKey返回最近插入记录的id
    Java map 详解
    Statement和PreparedStatement的异同
    css3 @media支持ie8用respond.js 解决IE6~8的响应式布局问题
    apply和call
    兼容性问题:backgroud-size支持IE8浏览器的方法
    json对象和json字符串之间的转化
  • 原文地址:https://www.cnblogs.com/bincoding/p/7764793.html
Copyright © 2011-2022 走看看