Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-2008, 02:07 AM
jiggsroger jiggsroger is offline
Newbie
 
Join Date: Apr 2008
Posts: 8
Rep Power: 0
jiggsroger is on a distinguished road
Question need help with drag and drop of control

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();
        }
Hoping for a solution,
-
Roger
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-15-2008, 07:23 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,517
Last Blog:
Web slideshow in JavaS...
Rep Power: 46
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: need help with drag and drop of control

Try an "if" statement to check whether the panel is out of the bounding rectangle of the form.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 07:29 AM
jiggsroger jiggsroger is offline
Newbie
 
Join Date: Apr 2008
Posts: 8
Rep Power: 0
jiggsroger is on a distinguished road
Unhappy Re: need help with drag and drop of control

Hi Xav,
the if is ok, i cant figure wat to put in the if()!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 02:01 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,517
Last Blog:
Web slideshow in JavaS...
Rep Power: 46
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: need help with drag and drop of control

Hmm... try drawing a diagram, to help you see. You might need for different conditions:

1. if the left side is touching the left side of the form.
2. if the top side is touching the top side of the form.
3. if the bottom side is touching the bottom side of the form.
4. work out the last one yourself...

Try and work a condition that uses these four.

Xav
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-16-2008, 12:58 AM
jiggsroger jiggsroger is offline
Newbie
 
Join Date: Apr 2008
Posts: 8
Rep Power: 0
jiggsroger is on a distinguished road
Unhappy Re: need help with drag and drop of control

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-16-2008, 12:48 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,517
Last Blog:
Web slideshow in JavaS...
Rep Power: 46
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: need help with drag and drop of control

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:
If the left side is touching the left side AND the right side is touching the right side AND the top side is touching the top side AND the bottom side is touching the bottom side (ALL at the same time!) then lock movement.
You see the problem? You need to use the operator OR, which in C# is not "&&", but "||". Try it with this - make your program halt dragging if any one of the conditions is met (i.e. if any borders are being hit).
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-17-2008, 03:49 AM
jiggsroger jiggsroger is offline
Newbie
 
Join Date: Apr 2008
Posts: 8
Rep Power: 0
jiggsroger is on a distinguished road
Default Re: need help with drag and drop of control

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-17-2008, 11:17 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,517
Last Blog:
Web slideshow in JavaS...
Rep Power: 46
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: need help with drag and drop of control

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."
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-18-2008, 01:51 AM
jiggsroger jiggsroger is offline
Newbie
 
Join Date: Apr 2008
Posts: 8
Rep Power: 0
jiggsroger is on a distinguished road
Thumbs up Re: need help with drag and drop of control

Hey Xav!
Got it! and it woiks!

Thanks Mate!
Roger
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-18-2008, 10:51 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,517
Last Blog:
Web slideshow in JavaS...
Rep Power: 46
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: need help with drag and drop of control

You're welcome!
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 11:20 PM.

Contest Stats

Xav ........ 162.68
Sacback ........ 120.05
alearb8 ........ 120.05
tfusion ........ 120
amr2107 ........ 120
d3s!gn ........ 120
Qoolman21 ........ 120
Pillager ........ 108
satrian ........ 100
neerlin ........ 100

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 68%

Ads