Hello everyone
I have a problem.
i want to make a form with movable command buttons.
the aim is that these buttons will represent the computers that are installed in one room.
or the tables in one bar.
all the tables can change depending the order that user give.
can anyone knows how can i do it?

Recommended Answers

All 11 Replies

I don't think using command buttons is the best option for this.

So how can i do it?

Do you have any code that you are working on ?

No. That's why i thought that is better to make command buttons movable
if you have any idea please let me know.

You need to put some effort and post the code here. We can modify it and make it work.

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

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

Can you post the example?

commented: What you think the previous couple of posts are ? -3

Can you post the example?

This is what happens when someone is spoon feed.

This is what happens when someone is spoon feed.

this is what happens when a dick-head called debasisdas thinks that is smart

commented: what an ignorant and unpleasant person you are, please read the rules and be a little more mature in your responses -3
commented: misbehaving idiot -3

No, He has a point, you put zero effort into solving your problem, and expect people to do all the code for you.

This is a place to seek help, not a place to get code from scratch.

Sure, I can do this for you, give you fully functional code but you wont learn anything then?

Don't expect everyone to just code on demand. They all have real life's, and jobs to do. So try to put some effort into learning how to code, then just sit here and expect people to feed it to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.