Link to home
Start Free TrialLog in
Avatar of porkVT
porkVT

asked on

Need to reload main form

I currently have a control array of buttons that are dynamically created in the form_load event based on input from a .ini file.  I am providing the user a way to modify this .ini file within my application.  however, if they add or delete an entry from the file, i have no way to be able to update the buttons on the main form to reflect this.

I thought about moving the button creation code into the Paint event, but it won't let me remove controls from there.

Only solution I could come up with is to launch another instance of my application and close the existing one.  It seems kinda crude though, and I'd like to find a better way.  Any suggestions?
Avatar of Z_Beeblebrox
Z_Beeblebrox

You could create a subroutine on your form which is responsible for unloading any existing buttons, then loading them based on the ini file. Call this subroutine from your form_load and from wherever you get notified that the ini file has changed.

Zaphod.
Avatar of JR2003
Have an application level variable in a module called something like
Public frmMainRef As frmMain

Have a procedure in a module called say ReloadMainForm

With the following code in the module:
Option Explicit
Public frmMainRef As Form1

Public Function ReloadMainForm()
    Set frmMainRef = New Form1
    frmMainRef.Show
End Function


And the following code in the form and a command button:

Option Explicit
Private Sub Command1_Click()
    Unload Me
    ReloadMainForm
End Sub


Everything in your application that needs to refer to the main form should just refer to the global variable frmMainRef.

JR
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial