Pass value back to MDI form from child from (class)
I have created a Windows Application in which one MDI form (frmMainForm) and several child form.
Application is working fine but Now I want to breake the child forms in a class (.dll) and call them into main project.
In Current project "mainmodule" - I have assign MDI form as
HTML Code:
Public MainForm As New frmMainMenu
frmMainMenu contain the "StatusBar1" for message display
In child form (frmComp) I used to display the text in StatusBar panel like -
HTML Code:
MainForm.StatusBar1.Panels(2).Text = "Saving Record..."
Now I create a class file in which copy "frmComp"
code like -
HTML Code:
Public gl_strScreenName As String
Public gl_strUserName As String
Public MainForm As System.Windows.Forms.Form
Public Sub New(ByVal ScreenName As String, ByVal UserName As String, ByVal mForm As Form)
MyBase.New()
'This is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent()
End Sub
But code like earlier show error message "'StatusBar1' is not a member of 'System.Windows.Forms.Form'" -
HTML Code:
MainForm.StatusBar1.Panels(2).Text = "Saving Record..."
Pls guide how to rectify the error and display the message in statusbar panel
Re: Pass value back to MDI form from child from (class)
First change your way of thinking. At the moment you're trying to get your form to push a status to the parent form directly. As you've discovered, that doesn't work for a number of reasons... 1) it's just bad juju to begin with. The form shouldn't care if it's a child form or a parent form or a stand alone form... 2) "MainForm" is just a form... a basic, empty and generic ordinary run of the mill, garden variety form. It's got nothing on it... that's why the attempt a calling STatusBar1 on it fails...
What you should be doing is in your child form(s), is creating an event, for example "ChangeStatus" ... and then raising that event along with the message you want to send as the status. Then in the main form, when you instanciate the child form, also wire up the event to the appropriate event handler, which then can take hte message and send it to the StatusBar properly.
-tg