添加到TabPage的MDIChild用户控件的焦点

添加到TabPage的MDIChild用户控件的焦点

问题描述:

亲爱的所有人,

我正在尝试找到一种在MDI父项的TabControl内使用MDI子项(恰好是用户控件)的方法.我可以使用...将用户控件的多个实例放到选项卡上.

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);
}



(数据列表是表单上的控件),以识别何时单击了标题栏.这样会将实例置于最前面,但似乎没有使其具有焦点,并且标题栏保持为未选定"颜色.

在其他所有方式中,代码的行为均应如预期.每个实例都有自己的数据,它会按预期显示和更新.

是否允许将MDI表单放入这样的容器控件中?我应该在寻找替代解决方案吗?还是我只是缺少一些真正明显的东西.

我应该补充一点,我已经看了与TabControl和MDI相关的有关codeproject的许多文章-请注意,我不希望每个用户控件都成为其自己的选项卡-我想拥有该控件的多个实例每个标签-希望清晰明了且有意义.

感谢您提供的建议和时间.

Aero



(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

看看类似的讨论: ^ ]
Take a look at similar discussion: How to Open Child Window in tab[^]


这是使用MDI子级的最佳方法:从不使用MDI.

这是一个主意:谁曾经需要MDI?为什么要折磨自己并吓users用户?
帮自己一个忙:完全不要使用MDI.没有设计,您可以更轻松地实现设计,并且质量更高.即使Microsoft也不鼓励使用MDI,实际上,Microsoft已将其从WPF中删除,并且几乎不支持它.更重要的是,如果您使用MDI,则会吓跑所有用户.只是不要.我可以解释该怎么办.

但是首先,看看您在做什么.选项卡界面本身在不同控件容器,选项卡之间扮演选择器的角色.它并非旨在与MDI一起使用,并且MDI…并非旨在托管在MDI客户端(由MDI Container实施)与MDI Children之间的预期关系之外的任何地方.您正在尝试滥用已经是一种滥用的东西. :-)

请参阅:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [如何在WPF中创建MDI父窗口? [ ^ ].

并且还请查看我过去的答案以解释该怎么做:
在WPF中使用MDI窗口的问题 [ ^ ],
MDIContainer提供错误 [如何设置最大化的子表单,最后一个子表单最小化 [ ^ ].

祝你好运,
—SA
Here is the best way of using MDI child: never using MDI.

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don''t. I can explain what to do instead.

But first, look at what you are doing. The tab interface itself plays the role of the selector between different control containers, tabs. It is not designed to work with MDI, and MDI… is not designed to be hosted anywhere except intended relationship between MDI client (implemented by MDI Container) and MDI Children. You are trying to abuse something which is already a kind of abuse. :-)

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

And please also see my past answers explaining what to do:
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last child form minimized[^].

Good luck,
—SA