C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Drag Drop WinForm Control at RunTime


Posted Date: 26 Aug 2008    Resource Type: Code Snippets    Category: Winforms Controls

Posted By: Ritesh N. Jain       Member Level: Gold
Rating:     Points: 10



Many time we come across situation where user need to reposition the Form's control at RunTime.Below is simple solution for that,For sanmple purpose i am using Picture Box control but same logic can be applied to any other WinForm Control


Dim isDragged As Boolean = False
Dim ptStartPosition As Point
'Handled the MouseDown event,In that if User has clicked the Left button than Capture the Starting coordinate of mouse.
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then
isDragged = True
ptStartPosition = New Point(e.X, e.Y)
Else
isDragged = False
End If
End Sub

'Once Mouse is Up Reset the boolen Flag
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
isDragged = False
End Sub
'InMousemove event perform the actual Transition of Control.
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If isDragged Then
Dim ptEndPosition As Point
'Set the New Transition point for Picturebox based on current mouse position and add appropriate offset to reduce flickering
ptEndPosition = PictureBox1.PointToScreen(New Point(e.X, e.Y))
ptEndPosition.Offset(-ptStartPosition.X, -ptStartPosition.Y - PictureBox1.Height)
PictureBox1.Location = ptEndPosition
End If
End Sub




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Drag Drop winform Picture box Mouse  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Displaying Directory Structure of Local Hard Drive
Previous Resource: Complete Numeric TextBox
Return to Discussion Resource Index
Post New Resource
Category: Winforms Controls


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference calls

Contact Us    Privacy Policy    Terms Of Use