Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI application using toolbar 1

Status
Not open for further replies.

stx

Programmer
Sep 24, 2002
62
BE
I have a toolbar on my parent form. When one of the buttons is pushed, i.e the save button, i want to run the save routine from the child form that currently has the focus. I vb6 i wrote in the toolbar_click event on the parent-form following code:
select case button.key
case = "save"
activeform.save
...
So when a toolbarbutton was pressed the save-routine of the activeform was executed. How can i do this in .NET?

thnx for the help.
 
Hi stx,

I haven't tried this but even in VB .NET we have something like

Form.ActiveForm so what you should be doing is

Dim currentForm As Form = Form.ActiveForm would give you the handle to the form that is currently active.
 
Hi Kris11

I implemented the code you suggested.
but if i want to write the following:

Code:
 currentform.save

I get the following error:
'save' is not a member of 'system.windows.forms.form'

Although I declared the save-function on my child-form as public I always get the same error.

Any thoughts?

 
Stx,

There are two approaches what we can do here, first wapproach is

1. Instead of declaring the variable as Form we have to do as follows

Dim currentForm As Object = Form.ActiveForm

And then you would be able to do whatever you were doing before.

2. But the better approach is that, create an ancestor window and add all the methods to that window like "Saveform", "DeleteForm" etc. and inherit all your forms from this ancestor and

Dim currentForm As frmAncestor = Form.ActiveForm

frmAncestor.saveForm() will work just fine.

Let me know if this works for you...
 
Kris11

I still get errors.
An unhandled exception of type 'system.missingmemberexecption' occurred in microsoft.visualbasic.dll
Public member 'save' on type 'frmmain' not found.

This is what i wrote in my frmmain form containing my toolbar:

Code:
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        Select Case ToolBar1.Buttons.IndexOf(e.Button)
            Case Is = 0
                Dim frm As Object = Form.ActiveForm
                frm.save()
        End Select
    End Sub

My childform that is active on the moment of pressing the toolbar contains a public sub save().

How can i fire this routine from my toolbar on my parent form (frmmain).

thnx
 
stx,

The reason for this error is because for some reason ActiveForm is always returning Nothing when we call Form.ActiveForm so instead can you try Me.ActiveMdiChild. Let me know if this works
 
Everything works now !

Thnx for your help kris11.
 
I have the same issue but in reverse. I've got the toolbar on the MDI executing whatever child form functions I need.

Now I have to figure out how to change various MDI toolbar properties from the child form at run-time.

Any thoughts?

Oli
 
Never mind. I had
Dim frmMDIvar As frmMDI = ParentForm
declared as a variable at the top of my child for and was getting errors when it tried to load. When I put the same code in at the function level everything worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top