|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hello folks,
I have a panel on a form with several other controls on it. The panel has to be a totally draggable over the form - and stop at that. Draggable only over the form! This is how I have implemented the drag and drop currently (see code block below). I need to ensure that the draggable panel doesn't tread beyond the form area irrespective of the form's size. I tried meddling with the height, location et all but then either it stops scrolling or doesn't come inside the form when i click. can you please tell me how to ensure that the whole panel stays within the form(that is not even the corners go out of form)? Code:
private void myDock_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
Invalidate();
}
private void myDock_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true;
clickOffsetX = e.X;
clickOffsetY = e.Y;
this.Invalidate();
}
private void myDock_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging == true)
{
myDock.Left = e.X + myDock.Left - clickOffsetX;
myDock.Top = e.Y + myDock.Top - clickOffsetY;
this.Invalidate();
}
Invalidate();
}
- Roger |
| Sponsored Links |
|
|
|
|||||
|
Try an "if" statement to check whether the panel is out of the bounding rectangle of the form.
|
|
|||
|
Xav, this is wat i was trying but it totally locks my movement.
if ((myDock.Left > this.Left) && (myDock.Top > this.Top) && (myDock.Bottom < this.Bottom) && (myDock.Right < this.Right)) myDock is the panel and 'this' the form.. i dunno if i am using the wrong properties to check the perimeter.. could use more help.. thanks in advance, Roger |
| Sponsored Links |
|
|
|
|||||
|
Ah... now I see the problem. You are using the boolean comparison operator "&&" (AND). At the moment, this is what it says in English...
Quote:
|
|
|||
|
Hi again,
if((myDock.Left > this.Left) || (myDock.Top < this.Top) || (myDock.Bottom < this.Bottom) || (myDock.Right < this.Right)) did this but it doesnt prevent the pane from going out of boundary. what properties else do i look for? |
|
|||||
|
Maybe the properties are wrong. What do "left", "right", "top" and "bottom" mean? Think about it logically - you want something like "if the right hand side of the panel is off the edge of the form, then cut movement."
|
|
|||||
|
You're welcome!
![]() |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Drag 'n drop | Automic | C# Programming | 1 | 03-31-2008 11:53 AM |
| File drag and drop | xxarmoxx | Java Help | 1 | 02-03-2008 11:19 AM |
| How to Drop Items on Listbox ? | kresh7 | Visual Basic Programming | 4 | 01-05-2008 03:05 PM |
Goal: 100,000 Posts
Complete: 68%