470,833 Members | 1,858 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

How to Click button by code

Hi, I'm try to learn vb.net.

in delphi have .click method for click button by coding.
Can I do that with vb.net

Thank you very much.
Apr 10 '07 #1
12 64408
On Apr 10, 10:34 am, "Thammarat charoenchai." <apa...@gmail.com>
wrote:
Hi, I'm try to learn vb.net.

in delphi have .click method for click button by coding.
Can I do that with vb.net

Thank you very much.
myButton.PerformClick()

Thanks,

Seth Rowe

Apr 10 '07 #2
Call the method that handles the Click event of the button you want to click
and pass it sender and e.

If the function/sub that you want to call the button click from isn't
already being passed send As Object and e as System.EventArgs then you will
have to Dim/declare out your own.

Dim sender as Object
Dim e as System.EventArgs
btnAdd_Click( sender, e)

'This is the sub/method that gets called when the button is clicked
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click

' Some code goes here

End Sub

'Here is an example that already is being passed sender and e As
System.EventArgs
Private Sub ContextMenuStrip1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ContextMenuStrip1.Click

'Some code

'Click the button
btnAdd_Click( sender, e)
End Sub

Hope that helps,

Chris

"Thammarat charoenchai." <ap****@gmail.comwrote in message
news:ua**************@TK2MSFTNGP04.phx.gbl...
Hi, I'm try to learn vb.net.

in delphi have .click method for click button by coding.
Can I do that with vb.net

Thank you very much.

Apr 10 '07 #3
This works perfectly - but what if you want to actually see the button
visually being pressed?

Cheers,
Johnny J.
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
On Apr 10, 10:34 am, "Thammarat charoenchai." <apa...@gmail.com>
wrote:
>Hi, I'm try to learn vb.net.

in delphi have .click method for click button by coding.
Can I do that with vb.net

Thank you very much.

myButton.PerformClick()

Thanks,

Seth Rowe

Apr 10 '07 #4
That's much easier :o)
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
On Apr 10, 10:34 am, "Thammarat charoenchai." <apa...@gmail.com>
wrote:
>Hi, I'm try to learn vb.net.

in delphi have .click method for click button by coding.
Can I do that with vb.net

Thank you very much.

myButton.PerformClick()

Thanks,

Seth Rowe

Apr 10 '07 #5
It's working, but have some problem. This is my code

Private Sub frmProducts_FormClosing(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles
MyBase.FormClosing
Dim ee As System.EventArgs

btnSave_ItemClick(sender, ee)

End Sub
when build project it's show

Warning 1 Variable 'ee' is used before it has been assigned a value. A
null reference exception could result at runtime.
C:\Project\HiStore\HiStore\frmProducts.vb 30 35 HiStore

What does it mean ?

Thank you very much
Apr 10 '07 #6
Try

Dim ee As System.EventArgs=New System.EventArgs

/Johnny J.
"Thammarat charoenchai." <ap****@gmail.comwrote in message
news:e2**************@TK2MSFTNGP03.phx.gbl...
It's working, but have some problem. This is my code

Private Sub frmProducts_FormClosing(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles
MyBase.FormClosing
Dim ee As System.EventArgs

btnSave_ItemClick(sender, ee)

End Sub
when build project it's show

Warning 1 Variable 'ee' is used before it has been assigned a value. A
null reference exception could result at runtime.
C:\Project\HiStore\HiStore\frmProducts.vb 30 35 HiStore

What does it mean ?

Thank you very much

Apr 10 '07 #7
Perfect!!

Thank you very much. :D
Apr 10 '07 #8
On Apr 10, 11:17 am, "Johnny J?rgensen" <j...@altcom.sewrote:
Try

Dim ee As System.EventArgs=New System.EventArgs

/Johnny J.

"Thammarat charoenchai." <apa...@gmail.comwrote in message

news:e2**************@TK2MSFTNGP03.phx.gbl...
It's working, but have some problem. This is my code
Private Sub frmProducts_FormClosing(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles
MyBase.FormClosing
Dim ee As System.EventArgs
btnSave_ItemClick(sender, ee)
End Sub
when build project it's show
Warning 1 Variable 'ee' is used before it has been assigned a value. A
null reference exception could result at runtime.
C:\Project\HiStore\HiStore\frmProducts.vb 30 35 HiStore
What does it mean ?
Thank you very much
Or he can just do btnSave_ItemClick(sender EventArgs.Empty) and avoid
the variable declaration.

Thanks,

Seth Rowe

Apr 10 '07 #9
This works perfectly - but what if you want to actually see the button
visually being pressed?
Good Question! Perhaps you could do this by passing the appropriate
windows messages to the button via the windows api, but I don't know
if that would work. If you need this behavior you will probably need
to do a userdrawn button and just draw the "pressed" image before you
call the PerformClick method.

Thanks,

Seth Rowe

On Apr 10, 11:04 am, "Johnny Jörgensen" <j...@altcom.sewrote:
This works perfectly - but what if you want to actually see the button
visually being pressed?

Cheers,
Johnny J.

"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@o5g2000hsb.googlegro ups.com...
On Apr 10, 10:34 am, "Thammarat charoenchai." <apa...@gmail.com>
wrote:
Hi, I'm try to learn vb.net.
in delphi have .click method for click button by coding.
Can I do that with vb.net
Thank you very much.
myButton.PerformClick()
Thanks,
Seth Rowe
Apr 10 '07 #10
"Johnny Jörgensen" <jo**@altcom.seschrieb:
This works perfectly - but what if you want to actually see the button
visually being pressed?
<URL:http://dotnet.mvps.org/dotnet/code/controls/#PressButton>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Apr 10 '07 #11
"Thammarat charoenchai." <ap****@gmail.comschrieb:
It's working, but have some problem. This is my code

Private Sub frmProducts_FormClosing(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles
MyBase.FormClosing
Dim ee As System.EventArgs

btnSave_ItemClick(sender, ee)
='btnSave_ItemClick(sender, EventArgs.Empty)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Apr 10 '07 #12
On Apr 10, 12:22 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"Johnny Jörgensen" <j...@altcom.seschrieb:
This works perfectly - but what if you want to actually see the button
visually being pressed?

<URL:http://dotnet.mvps.org/dotnet/code/controls/#PressButton>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks for the link Herfried, I was just going through pinvoke.net
trying to find the appropriate message values - now I have to get back
to work :-(

Thanks,

Seth Rowe

Apr 10 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by yfng | last post: by
reply views Thread by [Yosi] | last post: by
5 posts views Thread by Steve | last post: by
5 posts views Thread by laziers | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.