Dear all,
I'm trying to find a way of using an MDI Child (which happens to be a user control) within a TabControl on the MDI Parent. I am able to put several instances of the user control onto a tab using...
Form NumForm = new NumericalViewer();
NumForm.TopLevel = false;
NumForm.MdiParent = this;
NumForm.Show();
tc_main.SelectedTab.Controls.Add(NumForm);
NumForm.BringToFront();
The above snippet is called every time a button is pressed on the parent form to bring a new instance of the numerical viewer onto the screen. This control has a standard 'Sizeable' border.
When you add a new instance, its always the last one added whose border shows that instance has the focus. All the others become deselected. I can select any of the other instances, but they never show as though they have the focus. I've even tried adding this...
protected override void DefWndProc(ref Message m)
{
const long WM_NCLBUTTONDOWN = 0xA1;
if (m.Msg == WM_NCLBUTTONDOWN)
{
this.Activate();
datalist.Select();
}
base.DefWndProc(ref m);
}
(datalist being a control on the form) to recognise when a titlebar has been clicked on. This brings the instance to the front but does not appear to give it focus, and the titlebar stays the "unselected" colour.
In every other way, the code behaves as it should. Each instance has its own data it which it displays and updates as intended.
Are you allowed to drop MDI forms into container controls like this? Should I be looking at an alternative solution? Or am I just missing something really obvious.
I should add that I have looked at a number of the articles on codeproject associated with the TabControl and MDI - note here that I don't want each user control to be its own tab - I would like to have multiple instances of the control per tab - hope that's clear and makes sense.
Thanks for any advice and time you can give.
Aero