Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace HelpingHF_CS
- {
- public class ChatBubble : Control
- {
- private Rectangle drawRect;
- public ChatBubble()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer |
- ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
- this.BackColor = Color.Transparent;
- this.MinimumSize = new Size(200, 46);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- var path = new GraphicsPath();
- path.AddArc(0, 0, 32, 32, 180, 90);
- path.AddArc(this.drawRect.Width - 42, 0, 32, 32, 270, 90);
- path.AddArc(this.drawRect.Width - 10, this.drawRect.Height - 32, 20, 32, 180, -90);
- path.AddArc(this.drawRect.Width - 16, this.drawRect.Height - 8, 32, 8, 90, 90);
- path.AddArc(this.drawRect.Width - 40, this.drawRect.Height - 8, 24, 8, 0, 90);
- path.AddArc(0, this.drawRect.Height - 32, 32, 32, 90, 90);
- path.CloseFigure();
- using (var fillBrush = new SolidBrush(Color.FromArgb(30, 150, 255)))
- {
- e.Graphics.FillPath(fillBrush, path);
- }
- using (var borderPen = new Pen(Color.FromArgb(35, 130, 220)))
- {
- e.Graphics.DrawPath(borderPen, path);
- }
- var textRect = new RectangleF(10, 10, this.drawRect.Width - 32, this.drawRect.Height - 20);
- e.Graphics.DrawString(this.Text, this.Font, Brushes.White, textRect);
- }
- protected override void OnSizeChanged(System.EventArgs e)
- {
- base.OnSizeChanged(e);
- ResetDrawRect();
- }
- protected void ResetDrawRect()
- {
- this.drawRect = new Rectangle(this.ClientRectangle.X,
- this.DisplayRectangle.Y,
- this.DisplayRectangle.Width - 1,
- this.DisplayRectangle.Height - 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment