0Hawk0

Chat Message

Dec 5th, 2017
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. using System.Windows.Forms;
  4.  
  5. namespace HelpingHF_CS
  6. {
  7.     public class ChatBubble : Control
  8.     {
  9.         private Rectangle drawRect;
  10.  
  11.         public ChatBubble()
  12.         {
  13.             SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer |
  14.                 ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
  15.  
  16.             this.BackColor = Color.Transparent;
  17.             this.MinimumSize = new Size(200, 46);
  18.         }
  19.  
  20.         protected override void OnPaint(PaintEventArgs e)
  21.         {
  22.             e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  23.  
  24.             var path = new GraphicsPath();
  25.             path.AddArc(0, 0, 32, 32, 180, 90);
  26.             path.AddArc(this.drawRect.Width - 42, 0, 32, 32, 270, 90);
  27.             path.AddArc(this.drawRect.Width - 10, this.drawRect.Height - 32, 20, 32, 180, -90);
  28.             path.AddArc(this.drawRect.Width - 16, this.drawRect.Height - 8, 32, 8, 90, 90);
  29.             path.AddArc(this.drawRect.Width - 40, this.drawRect.Height - 8, 24, 8, 0, 90);
  30.             path.AddArc(0, this.drawRect.Height - 32, 32, 32, 90, 90);
  31.             path.CloseFigure();
  32.             using (var fillBrush = new SolidBrush(Color.FromArgb(30, 150, 255)))
  33.             {
  34.                 e.Graphics.FillPath(fillBrush, path);
  35.             }
  36.             using (var borderPen = new Pen(Color.FromArgb(35, 130, 220)))
  37.             {
  38.                 e.Graphics.DrawPath(borderPen, path);
  39.             }
  40.  
  41.             var textRect = new RectangleF(10, 10, this.drawRect.Width - 32, this.drawRect.Height - 20);
  42.             e.Graphics.DrawString(this.Text, this.Font, Brushes.White, textRect);
  43.         }
  44.  
  45.         protected override void OnSizeChanged(System.EventArgs e)
  46.         {
  47.             base.OnSizeChanged(e);
  48.             ResetDrawRect();
  49.         }
  50.  
  51.         protected void ResetDrawRect()
  52.         {
  53.             this.drawRect = new Rectangle(this.ClientRectangle.X,
  54.                 this.DisplayRectangle.Y,
  55.                 this.DisplayRectangle.Width - 1,
  56.                 this.DisplayRectangle.Height - 1);
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment