By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

calling a control at runtime

P: n/a
SL
I have a packaged control that I want to work off a button. How do I call
it from btn_click()

For example:

Private Sub controlA_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles controlA.Click
End Sub

Private Sub btnControlA_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnControlA.Click
' here I want to call controlA_Click
End Sub

Any help would be appreciated.

S

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"SL" <no**@earthlink.net> wrote in
news:uw**************@TK2MSFTNGP09.phx.gbl:
I have a packaged control that I want to work off a button. How do I
call it from btn_click()

For example:

Private Sub controlA_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles controlA.Click
End Sub

Private Sub btnControlA_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnControlA.Click
' here I want to call controlA_Click
End Sub


controlA_Click(me, nothing)

Or you can use a RaiseEvent controlA.click

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #2

P: n/a

"SL" <no**@earthlink.net> wrote in message
news:uw**************@TK2MSFTNGP09.phx.gbl...
Private Sub btnControlA_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnControlA.Click
' here I want to call controlA_Click
End Sub


Lucas gave you the direct answer. I'll give you the stock answer that it's
generally considered bad practice to call control events directly. If the
code executed in an event handler may need to be called outside that event
handler, it's recommended that you put the code in a separate procedure and
call that procedure, both from inside the handler and wherever else you need
to call it. In this case, your sample code would look like:

Private Sub controlA_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles controlA.Click
ProcessControlA()
End Sub

Private Sub btnControlA_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnControlA.Click
ProcessControlA()
End Sub

Everything you used to have in controlA_Click needs to be moved to
ProcessControlA().
Nov 20 '05 #3

P: n/a
Hi SL,

You have in VBNet a lot of possibilities, the one from Lucas is very nice by
instance.

I myself use often call the event with
method(nothing, nothing), and then because it is nothing I know it is not
sended from an control.

However when you google this newsgroup on this you find a lot of methods,
there are at least 4 and nobody in this newsgroup could really prove why the
one was better than the other. Mostly a matter of taste.

I hope this helps?

Cor
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.