Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filled rubber band in Winforms Application

how can i draw a zero opacity rubber band over a windows form with 0.3 opacity? (The rubber band is made after a Microsoft example


Update:

I need that rubber band to work something like a mask. If you use Jing or any other screen shot tool, you will see EXACTLY what I need to do when do you try to make a screenshot: the screen goes semi-opaque and when you make the selection, you will see the 0 opacity selection

like image 326
andySF Avatar asked Jan 14 '10 15:01

andySF


3 Answers

Is this the droid you were looking for?

    public Form1()
    {
        InitializeComponent();
        DoubleBuffered = true;
    }

    bool mouseDown = false;
    Point mouseDownPoint = Point.Empty;
    Point mousePoint = Point.Empty;

    protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
        mouseDown = true;
        mousePoint = mouseDownPoint = e.Location;
    }

    protected override void OnMouseUp(MouseEventArgs e)
    {
        base.OnMouseUp(e);
        mouseDown = false;
    }

    protected override void OnMouseMove(MouseEventArgs e)
    {
        base.OnMouseMove(e);
        mousePoint = e.Location;
        Invalidate();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        if (mouseDown)
        {
            Region r = new Region(this.ClientRectangle);
            Rectangle window = new Rectangle(
                Math.Min(mouseDownPoint.X, mousePoint.X),
                Math.Min(mouseDownPoint.Y, mousePoint.Y),
                Math.Abs(mouseDownPoint.X - mousePoint.X),
                Math.Abs(mouseDownPoint.Y - mousePoint.Y));
            r.Xor(window);
            e.Graphics.FillRegion(Brushes.Red, r);
            Console.WriteLine("Painted: " + window);
        }
    }
like image 69
Dearmash Avatar answered Nov 14 '22 13:11

Dearmash


You need to use a partially opaque color when drawing:

Updated line from linked article, in the MyDrawReversibleRectangle method:

ControlPaint.DrawReversibleFrame( rc, Color.FromArgb(80, 120, 120, 120), FrameStyle.Dashed );
like image 43
Oded Avatar answered Nov 14 '22 14:11

Oded


I used the code that @Dearmash supplied in the screen capture utility that comes with my open source app BugTracker.NET. The app isn't very big, so if you are doing screen capture stuff, it might be a good starting point. More info here:

http://ifdefined.com/blog/post/Screen-capture-utility-in-C-NET.aspx

like image 43
Corey Trager Avatar answered Nov 14 '22 12:11

Corey Trager