tangxu
2024-11-04 ebd031e3bed6c1cfddce8fc9b98f7f9e95fb9e32
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Colors;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region HopePictureBox
 
    public class HopePictureBox : PictureBox
    {
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality;
        public PixelOffsetMode PixelOffsetType
        {
            get => _PixelOffsetType;
            set
            {
                _PixelOffsetType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics graphics = pe.Graphics;
            graphics.SmoothingMode = SmoothingType;
            graphics.PixelOffsetMode = PixelOffsetType;
            graphics.TextRenderingHint = TextRenderingType;
            graphics.Clear(Parent.BackColor);
 
            if (Image == null)
            {
                graphics.FillRectangle(new SolidBrush(BackColor), new RectangleF(0, 0, Width, Height));
            }
 
            base.OnPaint(pe);
 
            GraphicsPath backPath = RoundRectangle.CreateRoundRect(0, 00, Width, Height, 4);
            graphics.DrawPath(new(Parent.BackColor, 4), backPath);
        }
 
        public HopePictureBox()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
            DoubleBuffered = true;
            BackColor = HopeColors.PlaceholderText;
        }
    }
 
    #endregion
}