vb.net double click on button?

Hi Bradley,

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button1.Click
     i += 1
[/SIZE][SIZE=2][COLOR=#0000ff]     If[/COLOR][/SIZE][SIZE=2] i = 2 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]          MessageBox.Show("i was clicked twice") [COLOR=darkgreen]'change this with adequate action/code[/COLOR]
          i = 0
[/SIZE][SIZE=2][COLOR=#0000ff]     End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
Then you can improve it by canceling/reseting action if there is a longer gap/pause between 1st and 2nd click. You can do it by Thread.Sleep(pauseperiod) very easy.

Regards ;)
 
This is how I would do it:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) _
[/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button1.Click
[/SIZE][SIZE=2][COLOR=#008000]  'do first time stuff here
[/COLOR][/SIZE][SIZE=2]  MsgBox("one time click")
[/SIZE][SIZE=2][COLOR=#008000]  'remove the event handler
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]  RemoveHandler[/COLOR][/SIZE][SIZE=2] Button1.Click, [/SIZE][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][SIZE=2] Button1_Click
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

 
You're right, the question is really not easy to understand :)
 
my problem is this:

Imports System.Runtime.InteropServices
Imports Word

Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
Dim word As New Word.Application
Dim doc As Word.Document

'filter which files to open
Me.OpenFileDialog1.Filter = "Word Docs (*.doc)|*.doc|All files|*.*"

If Me.OpenFileDialog1.ShowDialog = DialogResult.OK Then

doc = word.Documents.Open(Me.OpenFileDialog1.FileName)
doc.Activate()
End If
End Sub
 
Back
Top