将子窗体添加到非 MDI win 窗体可防止子窗体内的子控件鼠标可点击 [英] Adding a child form to a Non MDI win form prevents child controls inside child form mouse clickable

查看:24
本文介绍了将子窗体添加到非 MDI win 窗体可防止子窗体内的子控件鼠标可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在父表单中添加子表单,但未将子表单的 MDI 父表单设置为父表单.以下是代码:

I am adding a child form inside a parent form without setting MDI parent of child form to parent form. Following is the code :

private void Form1_Load(object sender, EventArgs e)
{
    ChildForm openForm = new ChildForm();
    openForm.Show();
    openForm.Visible = true;
    openForm.TopLevel = false;
    this.Controls.Add(openForm);
}

在子窗体中的任何控件内单击文本只会完全选择文本,不允许直接使用鼠标编辑文本.不过,使用键盘编辑文本工作正常.

Clicking text inside any control within child form just selects the text completely and does not allow editing text directly using mouse. Editing text using keyboards is working fine though.

由于选项卡控件的一些其他问题,我无法设置 ChildForm.MDI= this.有什么办法可以防止这种情况发生并允许用户使用鼠标编辑文本.

I cannot set ChildForm.MDI= this because of some other issues with a tab control. Is there any way to prevent this and allow user to edit text using mouse.

推荐答案

考虑使用 UserControl 代替.它的设计方式与 Form 相同,但它没有边框,旨在用于其他表单中.

Consider using a UserControl instead. It is designed the same way as a Form but it does not have borders and it is intended to be used inside other forms.

您只需编译包含它的项目一次,以便它出现在 Visual Studio 工具箱中(假设该项目在同一个解决方案中,并且与包含 Form 的项目是同一项目)或引用它.

You only have to compile the project that contains it once so that it appears in Visual Studio toolbox (assuming the project is in the same solution and is either the same project as the one containing the Form or has a reference to it.

或者,您可以像在示例中所做的那样动态加载它.但是如果你系统地加载同一个单用户控件,在设计器中更容易做到...

Or alternatively, you can load it dynamically similar to what you have done in your example. But if you systematically load the same single user control, it is easier to do in the designer...

有时,您可能还想对布局进行一些调整.

Sometime, you might also want to make some adjustment to the layout.

这篇关于将子窗体添加到非 MDI win 窗体可防止子窗体内的子控件鼠标可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆