Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
i have to create windows application for drag and drop control in a form.i get code and can drag and drop in same form.and code is
VB
Private blnMoving As Boolean = False
 Private MouseDownX As Integer
 Private MouseDownY As Integer
 Private MovingRect As Rectangle
 Private oldRect As Rectangle
 Private blnClick As Boolean = False

 Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
     If e.Button = MouseButtons.Left Then
         blnMoving = True
         MouseDownX = e.X
         MouseDownY = e.Y
         MovingRect = New Rectangle(Button1.Location, Button1.Size)
     End If
 End Sub

 Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
     If e.Button = MouseButtons.Left And Not blnClick Then
         Button1.Location = Me.PointToClient(New Point(MovingRect.X, MovingRect.Y))
         Me.Refresh()
         oldRect = oldRect.Empty
         blnMoving = False
     Else
         blnClick = False
         blnMoving = False
     End If
 End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     blnClick = True
 End Sub

 Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
     If blnMoving Then
         If Not oldRect.IsEmpty Then
             ControlPaint.DrawReversibleFrame(MovingRect, Me.BackColor, FrameStyle.Thick)
             Button1.Refresh()
         End If

         Dim temp As Point = Me.PointToScreen(New Point(Button1.Location.X + (e.X - MouseDownX), Button1.Location.Y + (e.Y - MouseDownY)))

         MovingRect.X = temp.X
         MovingRect.Y = temp.Y

         If Me.ClientRectangle.Contains(Me.RectangleToClient(MovingRect)) Then
             oldRect = MovingRect
         Else
             MovingRect = oldRect
         End If
         ControlPaint.DrawReversibleFrame(MovingRect, SystemColors.Control, FrameStyle.Thick)
     End If
 End Sub


but my need is form main form if i click button it open one floating form and it contains controls,and form that folating form i need to click the control and drag and drop in main form.And also capture and save the location in form ,if i close application and open again i need to fix button in last time saved x and y axis location, so where i capture the x axis and y axis ? is it possible to capture x axis and y axis in sql server ?,and if i open again is possible to retrive data from sql server and give to controls ?
Is it possible ?

Regards
Aravind
Posted
Updated 19-Aug-13 19:35pm
v2

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