Vb[2008] MDI application - Menustrip Item used to activate a form.

  • Thread starter Thread starter Rob W
  • Start date Start date
R

Rob W

Greetings,

My notepad application create a new instance of a form for a MDI
application.

The code below create a new instance of form "text document" and creates a
menu item in the file menu strip option and assigns all new menu items to a
single event handler "documentToolStripMenuItem".

The plan was to use the sender property of the new created menustrip item to
switch between forms, with the selected menu item becoming the active form.

I've been looking at Ctype and Directcast and can't see how I can use a
property of type object to be used to pass in the form name or be converted
to type of form.

Document.Active()
(sender).Active()

Hope this is understandable, can anyone suggest a way forward?

In the mean time I am going to take a break then re-visit it.

Thanks
Rob


Private Sub NewCtrlNToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NewCtrlNToolStripMenuItem.Click,
NewToolStripButton.Click
Dim MDIChildForm As New textdocument()

MDIChildForm.MdiParent = Me

MDIChildForm.Text = "Document" & Me.MdiChildren.GetLength(0) 'Set document
title based on document number

MDIChildForm.Show()

'Add new menu item for each document opened

Dim FileNewMenuItem As New ToolStripMenuItem("Document" &
Me.MdiChildren.GetLength(0), Nothing, New EventHandler(AddressOf
documentToolStripMenuItem_Click))

FileToolStripMenuItem.DropDownItems.Add(FileNewMenuItem)
 
Greetings,

My notepad application create a new instance of a form for a MDI
application.

The code below create a new instance of form "text document" and creates a
menu item in the file menu strip option and assigns all new menu items toa
single event handler "documentToolStripMenuItem".

The plan was to use the sender property of the new created menustrip itemto
switch between forms, with the selected menu item becoming the active form.

I've been looking at Ctype and Directcast and can't see how I can use a
property of type object to be used to pass in the  form name or be converted
to type of form.

Document.Active()
(sender).Active()

Hope this is understandable, can anyone suggest a way forward?

In the mean time I am going to take a break then re-visit it.

Thanks
Rob

Private Sub NewCtrlNToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NewCtrlNToolStripMenuItem.Click,
NewToolStripButton.Click
Dim MDIChildForm As New textdocument()

MDIChildForm.MdiParent = Me

MDIChildForm.Text = "Document" & Me.MdiChildren.GetLength(0) 'Set document
title based on document number

MDIChildForm.Show()

'Add new menu item for each document opened

Dim FileNewMenuItem As New ToolStripMenuItem("Document" &
Me.MdiChildren.GetLength(0), Nothing, New EventHandler(AddressOf
documentToolStripMenuItem_Click))

FileToolStripMenuItem.DropDownItems.Add(FileNewMenuItem)

I'm not really sure what you are asking, but in the chance that all
you need is a menu item to switch between active child windows, that
is automatically setup when you add an MDIParent form to your project
using the template. It does this by setting the MenuStrip's
MdiWindowListItem property to the name of the menu item to be the
window list menu, which by default is the windowsMenu menu item.
 
Thanks, I just discovered that once I utilised the MdiWindowListItem (see
below) about 5 minutes ago :-)

MenuStrip1.MdiWindowListItem = Me.FileToolStripMenuItem

Greetings,

My notepad application create a new instance of a form for a MDI
application.

The code below create a new instance of form "text document" and creates a
menu item in the file menu strip option and assigns all new menu items to
a
single event handler "documentToolStripMenuItem".

The plan was to use the sender property of the new created menustrip item
to
switch between forms, with the selected menu item becoming the active
form.

I've been looking at Ctype and Directcast and can't see how I can use a
property of type object to be used to pass in the form name or be
converted
to type of form.

Document.Active()
(sender).Active()

Hope this is understandable, can anyone suggest a way forward?

In the mean time I am going to take a break then re-visit it.

Thanks
Rob

Private Sub NewCtrlNToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NewCtrlNToolStripMenuItem.Click,
NewToolStripButton.Click
Dim MDIChildForm As New textdocument()

MDIChildForm.MdiParent = Me

MDIChildForm.Text = "Document" & Me.MdiChildren.GetLength(0) 'Set document
title based on document number

MDIChildForm.Show()

'Add new menu item for each document opened

Dim FileNewMenuItem As New ToolStripMenuItem("Document" &
Me.MdiChildren.GetLength(0), Nothing, New EventHandler(AddressOf
documentToolStripMenuItem_Click))

FileToolStripMenuItem.DropDownItems.Add(FileNewMenuItem)

I'm not really sure what you are asking, but in the chance that all
you need is a menu item to switch between active child windows, that
is automatically setup when you add an MDIParent form to your project
using the template. It does this by setting the MenuStrip's
MdiWindowListItem property to the name of the menu item to be the
window list menu, which by default is the windowsMenu menu item.
 
Following on from this, another MDI applications query.

Can I use the menu items on the MDIContainer through a designer option
rather than manually coding them with

Friend WithEvents?

I looked but couldn't see an option on the menustrip object via properties
in the design menu.
 
To clairify I was to be able to modify the textbox within the newly created
forms via a menu item from the original MDI container.
 
To clairify I was to be able to modify the textbox within the newly created
forms via a menu item from the original MDI container.

I think what you want to look into the the MdiChildren collection and
the ActiveMdiChild properties.

ActiveMdiChild if you want to effect a control in the currently active
child window, or MdiChildren if you want to effect a control on a
child window that is not the current active child window. Of course,
if you are going to do something on a child in the MdiChildren
collection, you will need some way to identify the children and which
one you want to effect. Maybe use the Tag property.
 
Back
Top