Re-activate Form?

frankwhite

Well-known member
Joined
Nov 30, 2004
Messages
49
Programming Experience
Beginner
Hi, I was wondering is it possible to re-activate the current form? I have some coding which is in the form activate, and that coding needs to be run a few times but the only way I can get it to work is clicking on to another form and returning to the form. I have tried me.activate, or frmmain.activate but none seem to work.
 
Form.Activate event wil only be raised once when the form is activated. Any chance you can describe in more detail what you are trying to do as there maybe a different solution we can offer you.
 
you could make a subroutine with the code that needs to be run twice.

VB.NET:
Example:
 
Public sub MyCode
 
 Your code here
 
End Sub

Then in the Forms Activate call that sub routine and anywhere you need to run that routine call it from there also.

example

VB.NET:
Private Sub Form1_Activate()
 
     MyCode
 
End Sub
 
Private Sub Form1_Load()
 
   MyCode
      'More code goes here
 
End Sub
 
Hi, I was wondering is it possible to re-activate the current form? I have some coding which is in the form activate, and that coding needs to be run a few times but the only way I can get it to work is clicking on to another form and returning to the form. I have tried me.activate, or frmmain.activate but none seem to work.

Why dont you jsut call the activate method yourself?

i.e. in your WizzBang Function, just write this:

Form1_Activate(null, null)




remember event handlers are functions just like any other and can be called like any other

better still you shoudl break your funky code out into another function entirely, and call that from both your function and the Activate event handler
 
Mmmm, no Cjard. Not good advice to someone who is learning. It is not good practice to start calling event handlers as if they are just a normal method. The words to remember there are 'Event Handler' therefore should be run only in response to an event being raised. I also seriously doubt you'd ever do such a thing given your C# background? The better option is the latter in Cjard's post.
 
heh, well.. my C# background usually leads me to do the latter (break out and modularise the code) though I admit I did a lot of rougharse "Oh, just populate the TreeView in Form_Load and if I want to re-populate it, just call Form_Load() again" when I was knocking out quick n dirty apps in VB


Actually.. I dont think there is any problem in calling an event handler from elsewhere, from a logical point of view.. It depends on how much other stuff the handler does. If it does soemthing very simple and small i'll probably just do it. Slap slap! :) Also, i'll only generally do it if I can get away with supplying null for every argument - for event handler codes that use the arguments, i'll definitely break it out :D
 
Back
Top