943,740 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 7531
  • VB.NET RSS
Jul 17th, 2009
0

how to call an event inside another event

Expand Post »
i want to call the load event of the form inside the click event of the commant button depending upon certain condition
how can i do this?
Similar Threads
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009
Jul 17th, 2009
1

Re: how to call an event inside another event

Lets say that in the loadmain you set text for a label like this
Label1.Text = "Load Main"
But you want to do the same thing if you click a button, then create a function called for example
VBNET Syntax (Toggle Plain Text)
  1. private void SetLabel()
  2. {
  3. Label1.Text = "Load Main"
  4. }
then your load main will have this
VBNET Syntax (Toggle Plain Text)
  1. private void LoadMain()
  2. {
  3. SetLabel()
  4. }
and the button event
VBNET Syntax (Toggle Plain Text)
  1. private void buttonevent()
  2. {
  3. SetLabel()
  4. }

I hope you understand the idea. regards
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
432 posts
since May 2009
Jul 17th, 2009
0

Re: how to call an event inside another event

thnx
so basically u cannot call the event as such
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009
Jul 19th, 2009
0

Re: how to call an event inside another event

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Try
  3. MsgBox("Form Load")
  4. Catch ex As Exception
  5. MsgBox(ex.Message)
  6. End Try
  7. End Sub
  8.  
  9. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10. Try
  11. Call Form1_Load(sender, e)
  12. Catch ex As Exception
  13. MsgBox(ex.Message)
  14. End Try
  15.  
  16. End Sub

But i suggest u to write the form load code into procedure,& call that procedure on form load & on button click,instead of calling form load event again
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Problem with button
Next Thread in VB.NET Forum Timeline: How to drag/drop labels ,that created at run time





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC