calling a control at runtime

  • Thread starter Thread starter SL
  • Start date Start date
S

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
 
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
 
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().
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top