[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1094
  • Last Modified:

Getting the rectangle to draw a reversible frame around a panel

I have a user control with 4 panels around a panel in the center.

See http://img345.imageshack.us/img345/4454/dockingstation1lt.png how it looks like.

Each of the 4 surrounding panels has a "drag handle" on the side towards the center panel. The drag handle works like a splitter and allows to resize the panel. It appears whenever the mouse is over the border between two panels.

To indicate the selected area I wanted to draw a dashed reversible rectangle around the whole panel on mouse down over the drag handle. I tried to do this using ControlPaint.DrawReversibleFrame(rect, Color.DimGray, FrameStyle.Dashed);

I have no problems using this in simple constructs on a form following the examples on:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasspointtoscreentopic.asp

However, I have problems in getting the correct absolute positions to draw the reversible frame for each of my four rectangles if I use my control on a form with a menue.

What ever I tried to do, it looks to me that something like reversibleFrame.Location = control.PointToScreen(control.Parent.Location) does not calculate the correct location. My reversibleFrame appears somewhere on the screen but never exactly on my panels.

What are your suggestions?

Peter
0
pgloor
Asked:
pgloor
  • 3
  • 3
1 Solution
 
vo1dCommented:
could you post a screenshot of that please?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You need to use the container of the Panel...if this is the Form itself then:

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // draw the reversible frame
                Rectangle panelRect = this.RectangleToScreen(new Rectangle(panel1.Location, panel1.Size));
                ControlPaint.DrawReversibleFrame(panelRect, Color.DimGray, FrameStyle.Dashed);
            }
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // erase the reversible frame
                Rectangle panelRect = this.RectangleToScreen(new Rectangle(panel1.Location, panel1.Size));
                ControlPaint.DrawReversibleFrame(panelRect, Color.DimGray, FrameStyle.Dashed);
            }
        }

If the Form is not the container, then replace "this" with the name of the Panels container.
0
 
pgloorAuthor Commented:
Sorry, I still don't get it.

Please note:
1) I have 4 panels, called topPanel, leftPanel, bottomPanel, rightPanel.
2) The 4 panels are arranged around a fifth panel, the centerPanel (not interesting for the problem).
3) Inside each panel, at the border to the centerPanel, there is a small invisible component. I call this DragHandle.
4) The DragHandle appears as a gray line with a HSplit or VSplit cursor whenever the mouse is moved over it.
5) If the mouse button is pressed over the drag handle a reversible frame should be drawn around the enclosing panel.

To make the problem better visible I slightly changed the code to draw the reversible frame with a thick black line.

The following screenshot shows what happens if the mouse is down over the drag handle on the topPanel.
http://img172.imageshack.us/img172/1395/dockingtop6vc.png

The following screenshot shows what happens if the mouse is down over the drag handle on the leftPanel.
http://img475.imageshack.us/img475/5873/dockingleft4my.png

I hope this helps to better understand the problem.

Peter
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
pgloorAuthor Commented:
Sorry I forgot to mention: on the screenshots mentioned above you can also see the code I used to get the rectangle and to draw the reversible frame.

Peter
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If I understand you correctly, then you have this layout:

(excuse my ascii art please...)

+------------------------------+
|                                       |
|  Form                             |
|                                       |
| +--------------------------+ |
| |                                  | |
| |  Panel(s)                     | |
| |                                   | |
| | +----------------+          | |
| | |                     |          | |
| | | GrabHandle   |          | |
| | | in each Panel |         | |
| | +----------------+         | |
| |                                  | |
| +--------------------------+ |
|                                       |
+------------------------------+

Consequently, you need this kind of code:

        private void GrabHandle_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Control ctl = (Control)sender;
                Control ctlParent = ctl.Parent;
                Control ctlGrandParent = ctlParent.Parent;
                Rectangle panelRect = ctlGrandParent.RectangleToScreen(new Rectangle(ctlParent.Location, ctlParent.Size));
                ControlPaint.DrawReversibleFrame(panelRect, Color.DimGray, FrameStyle.Dashed);
            }
        }
0
 
pgloorAuthor Commented:
You are great!

ctlGrandParent.RectangleToScreen(new Rectangle(ctlParent.Location, ctlParent.Size)); did the trick!

So far I only tried:
  ctlParent.RectangleToScreen(new Rectangle(ctlParent.Location, ctlParent.Size))
  ctl.RectangleToScreen(new Rectangle(ctlParent.Location, ctlParent.Size))
  this.RectangleToScreen(new Rectangle(ctlParent.Location, ctlParent.Size))
and variations of them with different parameters.

I didn't realize the relation between the object where I'm calling the method from and the rectangle passed as the parameter. Now it's clear.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Glad I was able to write the code in a more understandable way.  =)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now