Tabcontrol on an MDI form

O

Ooogy

Hey there kind folks. Maybe someone out there can tell me where I'm
going wrong here.

I have a winform MDI app with a parent form ("MDIHMI.vb") and a child
form ("frmEMSearch"). On frmEMSearch, is a tab control with 4 tab
pages; the first one (index 0) is called "tabEpiDef". I have a menu
bar across the top of MDHMI where one of the options should bring
frmEMSearch up if it's not already of course, and if it is, switch
over to the tabEpiDef tab page.

In coding the click event for the menu item, no matter what I do, I
cant seem to bring the first tab page to the front. It seems like
I've tried everything. None of these seem to work (individually, or
in groups)...


frmEMSearch.Controls("TabControl1").Controls("tabEpiDef").BringToFront()
frmEMSearch.TabControl1.SelectedIndex = 0
newForm.TabControl1.SelectedIndex = 0

frmEMSearch.Controls("TabControl1").Controls("tabEpiDef").Select()

frmEMSearch.Controls("TabControl1").Controls("tabEpiDef").BringToFront()
frmEMSearch.TabControl1.SelectedIndex = 0
frmEMSearch.TabControl1.SelectedTab.BringToFront()
frmEMSearch.Controls("tabcontrol1").Select()
frmEMSearch.TabControl1.TabPages(0).Select()
frmEMSearch.TabControl1.TabPages(0).Show()
frmEMSearch.TabControl1.TabPages(0).BringToFront()
newForm.tabEpiDef.Select()
newForm.tabEpiDef.BringToFront()


newForm is instantiated immediately before all the above with...

Dim newForm As New frmEMSearch

Is there some sort of special way I'm not aware of to refer to a child
form in an MDI app? Can anyone give me a clue as to what direction I
should be looking to for an answer to this seemingly easy task?

Thanks VERY much in advance...Ooogy
 
A

Armin Zingler

Ooogy said:
Hey there kind folks. Maybe someone out there can tell me where I'm
going wrong here.

I have a winform MDI app with a parent form ("MDIHMI.vb") and a
child form ("frmEMSearch"). On frmEMSearch, is a tab control with 4
tab pages; the first one (index 0) is called "tabEpiDef". I have a
menu bar across the top of MDHMI where one of the options should
bring frmEMSearch up if it's not already of course, and if it is,
switch over to the tabEpiDef tab page.

In coding the click event for the menu item, no matter what I do, I
cant seem to bring the first tab page to the front. It seems like
I've tried everything. None of these seem to work (individually, or
in groups)...


frmEMSearch.Controls("TabControl1").Controls("tabEpiDef").BringToFront()
frmEMSearch.TabControl1.SelectedIndex = 0
newForm.TabControl1.SelectedIndex = 0

frmEMSearch.Controls("TabControl1").Controls("tabEpiDef").Select()

frmEMSearch.Controls("TabControl1").Controls("tabEpiDef").BringToFront()
frmEMSearch.TabControl1.SelectedIndex = 0
frmEMSearch.TabControl1.SelectedTab.BringToFront()
frmEMSearch.Controls("tabcontrol1").Select()
frmEMSearch.TabControl1.TabPages(0).Select()
frmEMSearch.TabControl1.TabPages(0).Show()
frmEMSearch.TabControl1.TabPages(0).BringToFront()
newForm.tabEpiDef.Select()
newForm.tabEpiDef.BringToFront()


newForm is instantiated immediately before all the above with...

Dim newForm As New frmEMSearch

Is there some sort of special way I'm not aware of to refer to a
child form in an MDI app? Can anyone give me a clue as to what
direction I should be looking to for an answer to this seemingly
easy task?

Thanks VERY much in advance...Ooogy


newform.tabcontrol1.selectedtab = newform.tabepidef

I'd put it inside frmEMSearch because both (explicit) references to
newform can be omitted.


Armin
 
O

Ooogy

newform.tabcontrol1.selectedtab = newform.tabepidef


Armin, thanks for the effort but unfortunately, still no luck.
Neither:

newForm.TabControl1.SelectedTab = newForm.tabEpiDef

or...

newForm.TabControl1.SelectedTab = newForm.tabEpiDef
newForm.TabControl1.SelectedTab.BringToFront()

or even...

newForm.TabControl1.SelectedTab =
newForm.Controls("TabControl1").Controls("tabEpiDef")

....seem to work. It just stays at the current tab and doesn't switch
over to tabEpiDef. Any other ideas for me to try?

Thanks...Ooogy
 
A

Armin Zingler

Ooogy said:
Armin, thanks for the effort but unfortunately, still no luck.
Neither:

newForm.TabControl1.SelectedTab = newForm.tabEpiDef

or...

newForm.TabControl1.SelectedTab = newForm.tabEpiDef
newForm.TabControl1.SelectedTab.BringToFront()

or even...

newForm.TabControl1.SelectedTab =
newForm.Controls("TabControl1").Controls("tabEpiDef")

...seem to work. It just stays at the current tab and doesn't
switch over to tabEpiDef. Any other ideas for me to try?

You wrote "where one of the options should bring frmEMSearch up if it's
not already of course"
Therefore I assumed that you create a new Form (by executing "New
frmEMSearch") only if it has not been created yet. Is this assumption
correct? I guess, you create a new Form each time even if there is
already one visible.


Armin
 
O

Ooogy

Exactly...here's what's not working...


Private Sub EpisodeDefinitionToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
EpisodeDefinitionToolStripMenuItem.Click
Dim newForm As New frmEMSearch()
newForm.MdiParent = Me
If IsNothing(newForm) Then
newForm.ShowDialog()
Else
If gCurrentTabIndex <> 0 Then
newForm.TabControl1.SelectedTab = newForm.tabEpiDef
End If
End If
End Sub


gCurrentTabIndex is set to the new tab index on TabControl1's
selectedindexchanged event.

Is my problem perhaps creating the new frmEMSearch even if it's
already there? How else other than the "If IsNothing(newForm)" would
I handle testing whether frmEMSearch currently is present? There are
of course other forms available to MDHMI to be a child and showing.

Thanks...Ooogy
 
J

Jack Jackson

Exactly...here's what's not working...


Private Sub EpisodeDefinitionToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
EpisodeDefinitionToolStripMenuItem.Click
Dim newForm As New frmEMSearch()
newForm.MdiParent = Me
If IsNothing(newForm) Then
newForm.ShowDialog()
Else

You are always creating a new form. You create a new frmEMSearch and
put its reference in newForm, and you set the new form's MdiParent
property. You then check the variable newForm for Nothing, but it
can't be Nothing because you just used it to set a property.

What I would do is create a class level property:

Private emSearch as frmEMSearch = Nothing

then change the code above to:

If emSearch Is Nothing Then
emSearch = New frmEMSearch
emSearch.MdiParent = Me
End If

If gCurrentTabIndex <> 0 Then
emSearcg.TabControl1.SelectedTab = emSearch.tabEpiDef
End If

emSearch.ShowDialog()
 
A

Armin Zingler

Ooogy said:
Exactly...here's what's not working...


Private Sub EpisodeDefinitionToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
EpisodeDefinitionToolStripMenuItem.Click
Dim newForm As New frmEMSearch()
newForm.MdiParent = Me
If IsNothing(newForm) Then

- newForm can never be nothing because you've just assigned a new object
to the variable
- General hint: "... Is Nothing" is shorter than calling a function
(IsNothing). Minor issue only.
newForm.ShowDialog()

Really Showdialog? In this case you could not use the menu again while
the modal form is shown.

Else
If gCurrentTabIndex <> 0 Then
newForm.TabControl1.SelectedTab = newForm.tabEpiDef
End If
End If
End Sub


gCurrentTabIndex is set to the new tab index on TabControl1's
selectedindexchanged event.

Is my problem perhaps creating the new frmEMSearch even if it's
already there? How else other than the "If IsNothing(newForm)"
would I handle testing whether frmEMSearch currently is present?
There are of course other forms available to MDHMI to be a child and
showing.


That's how I'd do it:


All in Class hdihmi:

private frmEMSearch as frmEMSearch

Private Sub EpisodeDefinitionToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
EpisodeDefinitionToolStripMenuItem.Click

if frmEMSearch is nothing then
frmEMSearch = New frmEMSearch()
addhandler frmEMSearch.formclosed,addressof OnEMSearchClosed
frmEMSearch.mdiparent = me
frmEMSearch.show
else
frmEMSearch.Activate

frmEMSearch.TabControl1.SelectedTab = frmEMSearch.tabEpiDef 'see
notes below
End Sub

protected overriadable sub OnEMSearchClosed

frmEMSearch = Nothing

end sub

However, I still don't understand how 'Showdialog' fits in your code.
I'm not sure /when/ you want to activate the TabPage. Only when the Form
is shown or also if it is reactivated?


Armin
 
O

Ooogy

Jack / Armin -

Got things working now as they should. For a while there, I was
getting a duplicate copy of frmEMSearch showing over the original; but
only the first time I clicked the menu item. After that, the new form
would switch to the proper tab as expected. Resolved that by setting
EMSearch to the initial "New frmEMSearch" call in MDIHMI's load event.

Thanks very much for the help...Ooogy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top