Move a control at runtime?

  • Thread starter Thread starter Mark Gaeth
  • Start date Start date
M

Mark Gaeth

Greetings,

I was lucky one time to have someone provide me a little code that would
allow the user to move a control at runtime. However, I lost that code
snippet when my hard drive failed and now after rebuilding most of the
program from scratch I am in need of that code again. I think it had to do
with getting the x,y of the screen location but I am dazed and confused. I
am a novice programer trying to make a program work for my model railroad
layout and need this to create a dispatcher panel.

Thanks in advance for any assistance.

Mark Gaeth
Decatur, IN
 
Hi,

If you want to move a control in runtime, you can use the left and right
properties of this control.

For example, for the button control:

Button1.Left = Button1.Left + 60
Button1.Top = Button1.Top + 60



Best regards,

Jorge Serrano Pérez
MVP VB.NET
 
Hi,

http://www.onteorasoftware.com/downloads/movecontrol.zip

Ken
-----------------

Greetings,

I was lucky one time to have someone provide me a little code that would
allow the user to move a control at runtime. However, I lost that code
snippet when my hard drive failed and now after rebuilding most of the
program from scratch I am in need of that code again. I think it had to do
with getting the x,y of the screen location but I am dazed and confused. I
am a novice programer trying to make a program work for my model railroad
layout and need this to create a dispatcher panel.

Thanks in advance for any assistance.

Mark Gaeth
Decatur, IN
 
Maybe this code can help you:

Private dragging As Boolean
Private beginX, beginY As Integer

Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown

dragging = True
beginX = e.X
beginY = e.Y

End Sub

Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
If dragging = True Then
Button2.Location = New Point(Button2.Location.X + e.X -
beginX,Button2.Location.Y + e.Y - beginY)
Me.Refresh()
End If
End Sub

Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp

dragging = False

End Sub

Greetz Peter
 
Thanks everyone for your kind response and code snippets. They worked
for what I was doing. Now I just need to play with it and see what I
need to do next. I know I will need to create "as needed" new contols of
the same type so they can be moved around in a text box with the
operators assigned train number and name.

Thanks again for the link as I sure I will find new stuff and ideas for
the novice newbie.

Mark Gaeth
Decatur, IN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top