I want to add several forms to an UltraTabbedMdiManager.
On activating a form, I want this form to be replaced with an alternative form (that has different functionality). Is this possible? (i.e. to replace a form with another form)
If this is not possible I plan to add the forms on load, then on activating a form, I will create a new form (with the enhanced functionality) and dispose of the original form. Is it possible to insert the new form (to maintain the order of the mdi tabs, so it gives the appearance that it has been replaced), or to specify a new index for a form in the mdi tab order?
Many Thanks
I have not tried this, but I have a feeling you may run into problem with this approach. I would instead recommend a different approach. Take the controls from your "enhanced functionality" Form and instead add them to a UserControl. At run-time, add empty Forms as Mdi children. When the child Form is selected, create and add an instance of the UserControl to the empty Form. Set its Dock property to Fill so it occupies the entire Form area. This way you don't have to deal with switching out Forms.
Thanks for that Mike.
The problem is that we can't actually take that approach given the structure of our base forms (it would be extremely complex to implement this solution as unfortunately everything is far too integrated at a base level).
Even though you you not recommend it, do you think there is anyway to do this by replacing the form itself? Ensuring the tab order remains unchanged?
You can try using code similar to this, but once again, you may run into other problems with a complex application. I have only verifid this with a very simple sample:
public partial class ParentForm : Form{ private bool loading;
public ParentForm() { InitializeComponent(); }
private void Form1_Load( object sender, EventArgs e ) { this.loading = true;
SimpleForm form = new SimpleForm(); form.MdiParent = this; form.Text = "Form1"; form.Show();
form = new SimpleForm(); form.MdiParent = this; form.Text = "Form2"; form.Show();
form = new SimpleForm(); form.MdiParent = this; form.Text = "Form3"; form.Show();
this.loading = false;
foreach ( MdiTabGroup group in this.ultraTabbedMdiManager1.TabGroups ) this.ReplaceSimpleTab( group.SelectedTab ); }
private void ultraTabbedMdiManager1_TabSelecting( object sender, Infragistics.Win.UltraWinTabbedMdi.CancelableMdiTabEventArgs e ) { if ( this.loading ) return;
if ( this.ReplaceSimpleTab( e.Tab ) ) e.Cancel = true; }
private bool ReplaceSimpleTab( MdiTab selectedTab ) { if ( ( selectedTab.Form is SimpleForm ) == false ) return false;
MdiTabGroup group = selectedTab.TabGroup;
ComplexForm form = new ComplexForm(); form.Text = selectedTab.Form.Text; form.MdiParent = this; form.Show();
MdiTab tab = this.ultraTabbedMdiManager1.TabFromForm( form ); tab.MoveToGroup( group, selectedTab.Index ); group.SelectedTab = tab;
selectedTab.Form.Close(); return true; }}