| View previous topic :: View next topic |
| Author |
Message |
Orbit Advanced Cheater
Reputation: 0
Joined: 09 Dec 2007 Posts: 74
|
Posted: Sun Jul 06, 2008 9:06 am Post subject: VB2008-Moving your form with a button |
|
|
Hello Guys,
I want to ask how can i drag a form using a button
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Jul 06, 2008 10:06 am Post subject: |
|
|
| What do you mean using a button ? can't you just drag it ?
|
|
| Back to top |
|
 |
Orbit Advanced Cheater
Reputation: 0
Joined: 09 Dec 2007 Posts: 74
|
Posted: Sun Jul 06, 2008 10:40 am Post subject: |
|
|
| You can if you have the top bar visible but i am hiding it and now i want to move the form using a button
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sun Jul 06, 2008 2:34 pm Post subject: |
|
|
| Code: |
Me.Position.X = 0
Me.Position.Y = 0
|
or
I think.
Been a while since I've messed with that stuff.
_________________
|
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Sun Jul 06, 2008 4:05 pm Post subject: |
|
|
Try using:
| Code: | | Form1.Location = New Point(xValue, yValue). |
|
|
| Back to top |
|
 |
Orbit Advanced Cheater
Reputation: 0
Joined: 09 Dec 2007 Posts: 74
|
Posted: Tue Jul 08, 2008 7:57 am Post subject: |
|
|
| Sorry but Typhoon808 nor samuri25404 code works
|
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Tue Jul 08, 2008 8:31 am Post subject: |
|
|
| Code: | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Location = New Point(100, 100)
End Sub |
This seems to work for me.
|
|
| Back to top |
|
 |
Orbit Advanced Cheater
Reputation: 0
Joined: 09 Dec 2007 Posts: 74
|
Posted: Tue Jul 08, 2008 8:50 am Post subject: |
|
|
| Typhoon808 wrote: | | Code: | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Location = New Point(100, 100)
End Sub |
This seems to work for me. |
This doesnt work
I found the correct code it is
| Code: | Private blnMoving As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer
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
End If
End Sub
Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
If blnMoving Then
Dim temp As Point = New Point()
temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
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 Then
blnMoving = False
End If
End Sub |
+repped samuri25404
As he gave me the idea
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Tue Jul 08, 2008 9:19 am Post subject: |
|
|
the reason it did not work is because you did not tell anyone what you wanted to do, if you say moving with a button, we assume it is by pressing and it moves to a certain point
be more specific and we will help you more
_________________
|
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Tue Jul 08, 2008 9:24 am Post subject: |
|
|
Oh, I see what you want to do now.
This is a much easier way of dragging a form without use of API functions and mouse events:
http://www.planet-source-code.com/URLSEO/vb/scripts/ShowCode!asp/txtCodeId!3965/lngWId!10/anyname.htm
As Snootae said, be more specific and you will get an answer much quicker.
|
|
| Back to top |
|
 |
|