0

我有这个自定义控件:

public class DrawingArea : Panel
    {
        public DrawingArea()
        {
            SetStyle(ControlStyles.UserPaint |ControlStyles.DoubleBuffer, true);
        }

        /// <summary>
        /// Override this method in subclasses for drawing purposes.
        /// </summary>
        protected virtual void OnDraw(Graphics graphics)
        {

        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT

                return cp;
            }
        }

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            // Don't paint background
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            // Update the private member so we can use it in the OnDraw method
            Graphics graphics = e.Graphics;

            // Set the best settings possible (quality-wise)
            graphics.TextRenderingHint =
                System.Drawing.Text.TextRenderingHint.AntiAlias;
            graphics.InterpolationMode =
                System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            graphics.PixelOffsetMode =
                System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            graphics.SmoothingMode =
                System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            // Calls the OnDraw subclass method
            OnDraw(graphics);
        }
    }

我在这里继承它:

public class SelectScreen : DrawingArea
{
    public SelectScreen()
    {
        BackColor = System.Drawing.Color.Black;
        Size = new System.Drawing.Size(400, 400);
        BorderStyle = System.Windows.Forms.BorderStyle.None;
    }
}

和行动:

void Action()
        {
            CaptureScreen();
            selectScreen.Show();
            WindowState = FormWindowState.Maximized;
            selectScreen.BringToFront();
        }

基本上我想做的是,捕获屏幕,然后在它上面添加一个黑色透明屏幕,这样我以后可以用它来裁剪图片。

4

0 回答 0