Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am new to VB .NET and been awhile since I programmed with VB6. So bare with me. I have searching all over for the answer but will post now.

 

Using a command button, I would like to use it as the folowing:

When button is pressed down and keep it pressed, it will repeat the code I have in the sub for the button and once I have released the button it stops the code.

 

Is .net capable of doing this? and if so how? please :confused:

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

The timer idea works, and I've another idea for you!

 

This will work just fine and, as you're new to VB.net, you'll learn some cool things like multithreading programming :)

Try it and mess around with it! Any questions post them :p

 

 

On a form put a button and a labelm don't change their names, add this code and see it running (it's some counter thar resets every time it's presses. If you don't want it to reset declare the i var outside of the method...) Enjoy!

 

 

 

 

 

 

Private Down As Boolean = False

Private DownThread As Threading.Thread

 

Private Sub myMethod()

Dim i As Integer = 0

Do While Down

Me.Label1.Text = i.ToString

i += 1

Loop

End Sub

 

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown

Down = True

DownThread = New Threading.Thread(AddressOf myMethod)

DownThread.Start()

End Sub

 

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp

DownThread.Suspend()

Down = False

DownThread = Nothing

End Sub

Software bugs are impossible to detect by anybody except the end user.
Posted

Glad you got it working. I am not new to programming in .net, I use C# which is almost the same as vb.net except syntax.

 

Thanks for trying to help though, you'll be a benefit to the site. Maybe someone else will be inspired by your idea. :)

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...