yangyin
2025-03-27 b0de14c2670b9ff0079dacfb4b7457b438368f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#region Imports
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ChatBubbleRight
 
    public class ChatBubbleRight : Control
    {
        #region Variables
 
        private GraphicsPath Shape;
        private Color _TextColor = Color.FromArgb(52, 52, 52);
        private Color _BubbleColor = Color.FromArgb(192, 206, 215);
        private bool _DrawBubbleArrow = true;
        private bool _SizeAuto = true;
        private bool _SizeAutoW = true;
        private bool _SizeAutoH = true;
        private bool _SizeWidthLeft = false;
 
        #endregion
 
        #region Properties
 
        public override Color ForeColor
        {
            get => _TextColor;
            set
            {
                _TextColor = value;
                Invalidate();
            }
        }
 
        public Color BubbleColor
        {
            get => _BubbleColor;
            set
            {
                _BubbleColor = value;
                Invalidate();
            }
        }
 
        public bool DrawBubbleArrow
        {
            get => _DrawBubbleArrow;
            set
            {
                _DrawBubbleArrow = value;
                Invalidate();
            }
        }
 
        public bool SizeAuto
        {
            get => _SizeAuto;
            set
            {
                _SizeAuto = value;
                Invalidate();
            }
        }
 
        public bool SizeAutoW
        {
            get => _SizeAutoW;
            set
            {
                _SizeAutoW = value;
                Invalidate();
            }
        }
 
        public bool SizeAutoH
        {
            get => _SizeAutoH;
            set
            {
                _SizeAutoH = value;
                Invalidate();
            }
        }
 
        public bool SizeWidthLeft
        {
            get => _SizeWidthLeft;
            set
            {
                _SizeWidthLeft = value;
                Invalidate();
            }
        }
 
        #endregion
 
        public ChatBubbleRight()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
            DoubleBuffered = true;
            Size = new(130, 40);
            BackColor = Color.Transparent;
            ForeColor = Color.FromArgb(52, 52, 52);
            Font = new("Segoe UI", 10);
        }
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Shape = new();
 
            GraphicsPath _with1 = Shape;
 
            _with1.AddArc(0, 0, 10, 10, 180, 90);
            _with1.AddArc(Width - 18, 0, 10, 10, -90, 90);
            _with1.AddArc(Width - 18, Height - 11, 10, 10, 0, 90);
            _with1.AddArc(0, Height - 11, 10, 10, 90, 90);
 
            _with1.CloseAllFigures();
 
            Invalidate();
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
            Size TS = TextRenderer.MeasureText(Text, Font);
 
            if (_SizeAuto)
            {
                int WW = Width;
                if (_SizeAutoW && _SizeAutoH)
                {
                    Width = TS.Width + 15;
                    Height = TS.Height + 15;
 
                    if (_SizeWidthLeft)
                    {
                        Location = new(Location.X - (Width - WW), Location.Y);
                    }
                }
                else if (_SizeAutoW)
                {
                    Width = TS.Width + 15;
 
                    if (_SizeWidthLeft)
                    {
                        Location = new(Location.X - (Width - WW), Location.Y);
                    }
                }
                else
                {
                    int TH = 0;
 
                    using (Graphics CG = CreateGraphics())
                    {
                        SizeF SF = CG.MeasureString(Text, Font, Width - 17);
                        TH = (int)SF.Height;
                    }
 
                    Height = TH + 15;
                    //Height = TS.Height + 15;
                }
            }
 
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            Graphics _G = G;
 
            _G.SmoothingMode = SmoothingMode.HighQuality;
            _G.PixelOffsetMode = PixelOffsetMode.HighQuality;
 
            _G.Clear(BackColor);
 
            // Fill the body of the bubble with the specified color
            _G.FillPath(new SolidBrush(_BubbleColor), Shape);
 
            // Draw the string specified in 'Text' property
            _G.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(6, 7, Width - 15, Height));
 
            // Draw a polygon on the right side of the bubble
            if (_DrawBubbleArrow == true)
            {
                Point[] p =
                {
                    new(Width - 8, Height - 19),
                    new(Width, Height - 25),
                    new(Width - 8, Height - 30)
                };
 
                _G.FillPolygon(new SolidBrush(_BubbleColor), p);
                _G.DrawPolygon(new(new SolidBrush(_BubbleColor)), p);
            }
 
            G.Dispose();
 
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(B, 0, 0);
 
            B.Dispose();
        }
    }
 
    #endregion
}