I don't think using command buttons is the best option for this.
debasisdas
Posting Genius
6,968 posts since Feb 2007
Reputation Points: 722
Solved Threads: 457
Skill Endorsements: 20
Do you have any code that you are working on ?
debasisdas
Posting Genius
6,968 posts since Feb 2007
Reputation Points: 722
Solved Threads: 457
Skill Endorsements: 20
You need to put some effort and post the code here. We can modify it and make it work.
debasisdas
Posting Genius
6,968 posts since Feb 2007
Reputation Points: 722
Solved Threads: 457
Skill Endorsements: 20
Try this code to create a moving button from one location to another:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Namespace WindowsApplication9
Public Partial Class Form1
Inherits Form
Public Velocity As Integer() = New Integer(1) {}
Public count As Integer
Public Dest As System.Drawing.Point = New Point(394, 368), Temp As System.Drawing.Point
Public Sub New()
InitializeComponent()
End Sub
Public Function CheckV(a As Point, b As Point, Temp As Point, time As Integer) As Integer
Dim vx As Integer = 0, vy As Integer = 0
If time = 1 Then
Dim sx As String = Convert.ToString(a.X - b.X)
If Math.Abs(a.X - b.X) < 1 Then
Return 1
Else
If sx.Length > 2 Then
vx = (a.X - b.X) \ 100
ElseIf sx.Length = 2 Then
vx = (a.X - b.X) \ 10
Else
vx = 1
End If
End If
Return vx
ElseIf time = 2 Then
Dim sy As String = Convert.ToString(a.Y - b.Y)
If Math.Abs(a.Y - b.Y) < 1 Then
Return 1
Else
If sy.Length > 2 Then
vy = (a.Y - b.Y) \ 100
ElseIf sy.Length = 2 Then
vy = (a.Y - b.Y) \ 10
Else
vy = 1
End If
End If
Return vy
Else
Return 0
End If
End Function
Private Sub button1_Click(sender As Object, e As EventArgs)
button1.Enabled = False
For i As Integer = 0 To 1
Velocity(i) = CheckV(Dest, button1.Location, Temp, i + 1)
Next
timer1.Start()
End Sub
Public Function [Stop](a As Boolean, b As Boolean) As Boolean
If button1.Location = Dest Then
timer1.[Stop]()
Return True
ElseIf a = True AndAlso b = True Then
timer1.[Stop]()
Return True
Else
Return False
End If
End Function
Public Function Stopx() As Boolean
If Math.Abs(button1.Location.X - Dest.X) < 5 OrElse button1.Location.X = Dest.X Then
Return True
Else
Return False
End If
End Function
Public Function Stopy() As Boolean
If Math.Abs(button1.Location.Y - Dest.Y) < 5 OrElse button1.Location.Y = Dest.Y Then
Return True
Else
Return False
End If
End Function
Private Sub timer1_Tick(sender As Object, e As EventArgs)
Dim x As Integer = 0, y As Integer = 1
Dim stop__1 As Boolean = False, stopx__2 As Boolean = False, stopy__3 As Boolean = False
stopx__2 = Stopx()
stopy__3 = Stopy()
stop__1 = [Stop](stopx__2, stopy__3)
If stop__1 = False Then
If stopx__2 = False Then
Temp.X = button1.Location.X + Velocity(x)
End If
If stopy__3 = False Then
Temp.Y = button1.Location.Y + Velocity(y)
End If
button1.Location = Temp
End If
End Sub
End Class
End Namespace
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
This is anothe code I just did in a rush, what the code does, is when you click a button (even number) buttons moves, when you click it again (odd number) it stops, and so on...
My code only shows an example of the button movement down and right (at the same time).
What you have to do, is to change the directions (based on some facts and class variables). Play with the code a bit, maybe it can suit you.
Code:
Public Partial Class Form1
Inherits Form
Private thr As Thread
Private clicks As Integer
Private bStop As Boolean
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
If clicks Mod 2 = 0 Then
bStop = False
thr = New Thread(AddressOf Go)
thr.Start()
Else
bStop = True
thr.Join()
End If
clicks += 1
End Sub
Private Sub Go()
While (button1.Location.X + button1.Size.Width) < Me.Size.Width AndAlso Not bStop
Invoke(New moveBd(AddressOf moveButton), button1)
Thread.Sleep(50)
End While
End Sub
Private Delegate Sub moveBd(btn As Button)
Private Sub moveButton(btn As Button)
Dim x As Integer = btn.Location.X
Dim y As Integer = btn.Location.Y
btn.Location = New Point(x + 1, y + 1)
'goes 1 pixel into the right and down!!
End Sub
End Class
bye, bye
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Can you post the example?
This is what happens when someone is spoon feed.
debasisdas
Posting Genius
6,968 posts since Feb 2007
Reputation Points: 722
Solved Threads: 457
Skill Endorsements: 20