showing a black transparent box over picturebox with an Image

101 views Asked by At

I have this custom control :

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);
        }
    }

which I inherit from it here :

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

and on Action :

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

basically what am trying to do is, capture the screen , then add a black transparent screen over it , so I can use it to crop the picture later.

0

There are 0 answers