Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a simple windows Form project. the Form is named Form1 with a Button named button1. I put simple test to see how ControlPaint.DrawReversibleFrame() behaves:

if I removed the first statement, consequent frame will not be erased. please help me understand how this reversible Frame works:

ControlPaint.DrawReversibleFrame(rectangle1, SystemColors.Highlight, FrameStyle.Thick);


here is the code:
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DrawReversibleDemo01
{
    public partial class Form1 : Form
    {
        private Rectangle rectangle1 = new Rectangle(70, 70, 100, 150);

        public Form1()
        {
            InitializeComponent();
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Rectangle screenRectangle = Screen.PrimaryScreen.Bounds;

            if (screenRectangle.Contains(rectangle1))
            {
                ControlPaint.DrawReversibleFrame(rectangle1, SystemColors.Highlight, FrameStyle.Thick); //<=== if I removed this statement, no frame is erased
                rectangle1.Offset(20, 20);
                ControlPaint.DrawReversibleFrame(rectangle1, SystemColors.Highlight, FrameStyle.Thick);
            }
        }
    }
}


What I have tried:

tried many demos and still did not get firm grip on this method. I feel I missed a critical point somewhere.
Posted
Updated 24-May-22 19:30pm
v2

1 solution

The idea of DrawReversibleFrame is that you use it for mouse drag operations to select an area on an image for example: the first call removes the old frame, then the second draws it in it's new position.

So you shouldn't be calling it twice every time - call it once when the mouse goes down, twice when the mouse moves with the button down, and once again when the button is released.
 
Share this answer
 
Comments
Southmountain 25-May-22 10:47am    
now I get it: it is the iteration on rectangle1. if I commented out that statement, it will break this iteration and become another new kind of iterations.

also I find one of your past answer on this DrawReversibleFrame question. it really helps.

Thank you!
OriginalGriff 25-May-22 11:01am    
You're welcome!

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