windowcapture
исходный код / UI/Controls/DoubleBufferedPanel.cs

DoubleBufferedPanel.cs

38 строк · 1,115 байт · модуль UI
 1using System;
 2using System.Drawing;
 3using System.Windows.Forms;
 4
 5namespace WindowCapture.UI
 6{
 7    // Double-buffered panel to prevent flickering
 8    public class DoubleBufferedPanel : Panel
 9    {
10        public bool TransparentBackground { get; set; }
11
12        private const int WM_ERASEBKGND = 0x0014;
13
14        public DoubleBufferedPanel()
15        {
16            DoubleBuffered = true;
17            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
18            UpdateStyles();
19        }
20
21        protected override void WndProc(ref Message m)
22        {
23            if (m.Msg == WM_ERASEBKGND) { m.Result = (IntPtr)1; return; }
24            base.WndProc(ref m);
25        }
26
27        protected override void OnPaintBackground(PaintEventArgs e)
28        {
29            if (TransparentBackground)
30            {
31                // Clear to fully transparent (alpha=0) so parent's DWM blur shows through
32                e.Graphics.Clear(Color.FromArgb(0, 0, 0, 0));
33                return;
34            }
35            base.OnPaintBackground(e);
36        }
37    }
38}