yangyin
2025-02-24 b3b65a002fe68b1383314098790f5a153b87765f
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Child.Crown;
using System.Drawing;
using System.Windows.Forms;
using static DPumpHydr.WinFrmUI.RLT.Helper.CrownHelper;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region CrownScrollView
 
    public abstract class CrownScrollView : CrownScrollBase
    {
        #region Constructor Region
 
        protected CrownScrollView()
        {
            SetStyle
            (
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.ResizeRedraw |
                ControlStyles.UserPaint,
                    true
            );
        }
 
        #endregion
 
        #region Paint Region
 
        protected abstract void PaintContent(Graphics g);
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
 
            // Draw background
            using (SolidBrush b = new(ThemeProvider.Theme.Colors.GreyBackground))
            {
                g.FillRectangle(b, ClientRectangle);
            }
 
            // Offset the graphics based on the viewport, render the control contents, then reset it.
            g.TranslateTransform(Viewport.Left * -1, Viewport.Top * -1);
 
            PaintContent(g);
 
            g.TranslateTransform(Viewport.Left, Viewport.Top);
 
            // Draw the bit where the scrollbars meet
            if (_vScrollBar.Visible && _hScrollBar.Visible)
            {
                using SolidBrush b = new(ThemeProvider.Theme.Colors.GreyBackground);
                Rectangle rect = new(_hScrollBar.Right, _vScrollBar.Bottom, _vScrollBar.Width, _hScrollBar.Height);
 
                g.FillRectangle(b, rect);
            }
        }
 
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            // Absorb event
        }
 
        #endregion
    }
 
    #endregion
}