tangxu
2024-12-16 23fadc9cb0c09b665a1bbcef7eaf16f916045dc4
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
#region Imports
 
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotCard
 
    public class ParrotCard : Control
    {
        public ParrotCard()
        {
            SetStyle(ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
            Size = new Size(320, 170);
            BackColor = Color.Transparent;
            ForeColor = Color.White;
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The 1st half color of he gradient")]
        public Color Color1
        {
            get => color1;
            set
            {
                color1 = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The 2nd half color of he gradient")]
        public Color Color2
        {
            get => color2;
            set
            {
                color2 = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The 1st text")]
        public string Text1
        {
            get => text1;
            set
            {
                text1 = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The 2nd text")]
        public string Text2
        {
            get => text2;
            set
            {
                text2 = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The 3rd text")]
        public string Text3
        {
            get => text3;
            set
            {
                text3 = value;
                Invalidate();
            }
        }
 
        private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public PixelOffsetMode PixelOffsetType
        {
            get => _PixelOffsetType;
            set
            {
                _PixelOffsetType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        [Category("Parrot")]
        [Browsable(true)]
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
 
            Brush brush = new LinearGradientBrush(ClientRectangle, color1, color2, 135f);
 
            using (GraphicsPath graphicsPath = new())
            {
                graphicsPath.AddArc(Width - 10 - 2, 0, 10, 10, 250f, 90f);
                graphicsPath.AddArc(Width - 10 - 2, Height - 10, 10, 8, 0f, 90f);
                graphicsPath.AddArc(0, Height - 10 - 2, 8, 10, 90f, 90f);
                graphicsPath.AddArc(0, 0, 10, 10, 180f, 90f);
                graphicsPath.CloseFigure();
                e.Graphics.FillPath(brush, graphicsPath);
            }
 
            StringFormat stringFormat = new()
            {
                LineAlignment = StringAlignment.Center,
                Alignment = StringAlignment.Near
            };
 
            e.Graphics.PixelOffsetMode = PixelOffsetType;
            e.Graphics.TextRenderingHint = TextRenderingType;
 
            Rectangle r = new(2, 6, Width - 4, 26);
 
            e.Graphics.DrawString(text1, new Font(Font.FontFamily, Font.Size + 4f), new SolidBrush(ForeColor), r, stringFormat);
 
            stringFormat.Alignment = StringAlignment.Near;
 
            r = new Rectangle(2, Height / 2, Width - 4, Height / 4);
            e.Graphics.DrawString(text2, new Font(Font.FontFamily, (Font.Size * 2f) + 2f), new SolidBrush(ForeColor), r, stringFormat);
 
            stringFormat.Alignment = StringAlignment.Near;
 
            r = new Rectangle(2, (Height / 2) + (Height / 4), Width - 4, Height / 4);
            e.Graphics.DrawString(text3, new Font(Font.FontFamily, Font.Size + 2f), new SolidBrush(ForeColor), r, stringFormat);
        }
 
        private Color color1 = Color.DodgerBlue;
        private Color color2 = Color.LimeGreen;
 
        private string text1 = "Credit Card";
        private string text2 = "1357 2468 9013 5724";
        private string text3 = "Exp: 01/02 - 03/04";
    }
 
    #endregion
}