Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
3.80/5 (3 votes)
See more:
Hello to all
i am student now blocked by ControlPaint.DrawReversibleFrame method

private void Form1_MouseMove(object sender,
    System.Windows.Forms.MouseEventArgs e)
{

    // If the mouse is being dragged,
    // undraw and redraw the rectangle as the mouse moves.
    if (isDrag)

        // Hide the previous rectangle by calling the
        // DrawReversibleFrame method with the same parameters.
    {
        ControlPaint.DrawReversibleFrame(theRectangle,
            this.BackColor, FrameStyle.Dashed);

        // Calculate the endpoint and dimensions for the new
        // rectangle, again using the PointToScreen method.
        Point endPoint = ((Control) sender).PointToScreen(new Point(e.X, e.Y));

        int width = endPoint.X-startPoint.X;
        int height = endPoint.Y-startPoint.Y;
        theRectangle = new Rectangle(startPoint.X,
            startPoint.Y, width, height);

        // Draw the new rectangle by calling DrawReversibleFrame
        // again.
        ControlPaint.DrawReversibleFrame(theRectangle,
            this.BackColor, FrameStyle.Dashed);
    }
}


i don't understand why the former DrawReversibleFrame is used to hide the previous rectangle.and why the latter DrawReversibleFrame can Draw the new rectangle.
does it take turns to hide or draw a rectangle?

thanks in advance!
Posted
Updated 1-Mar-11 21:00pm
v2
Comments
Sergey Alexandrovich Kryukov 2-Mar-11 3:16am    
Why on Earth you ask what your code is doing? Is it because this is not your sample?
--SA
eromoe 2-Mar-11 3:51am    
yes,i want to make a program to crop image.and this sample is derived from MSDN.

1 solution

Because it is a Reversible Frame: When you draw it once, it appears, when you draw it again, it disappears. If you didn't draw it again, it would remain there until the control is invalidated.

If you think about Exclusive OR (XOR) operation:

0x23 XOR 0x17 = 0x34

0x34 XOR 0x17 = 0x23

0x34 XOR 0x23 = 0x17


A Reversible Frame does a similar thing on a bigger scale.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Mar-11 3:17am    
Nice and simple explanation, my 5. Hope OP knows how XOR works :-)
--SA
OriginalGriff 2-Mar-11 3:53am    
They do still teach OR, AND and XOR on programming courses, don't they? DON'T THEY? :panic:
eromoe 2-Mar-11 4:04am    
Regrettably,they don't...
we just learn what OR, AND and XOR are and how they work...
OriginalGriff 2-Mar-11 4:28am    
What is the difference between "teach" and "just learn"? :laugh:
eromoe 2-Mar-11 4:42am    
em,i think OR, AND and XOR on programming courses you mentioned is used to make some complex program.
we only learned fur.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900