简体   繁体   English

无法使用鼠标选择TextBox控件的文本

[英]Cannot select text of TextBox control with mouse

I want to embed a Form within another Form . 我要嵌入Form另一个内Form Here is what I have tried: 这是我尝试过的:

private void Form1_Load(object sender, EventArgs e)
{
    Form2 form = new Form2();  
    form.TopLevel = false;  
    panel1.Controls.Add(form);  
    form.Dock = DockStyle.Fill;  
    form.Show();  
}

Form1 is the parent form. Form1是父窗体。 Form2 is the child form, which has a TextBox control. Form2是子窗体,它具有TextBox控件。

The problem: After embedding the child form, the TextBox in the child form cannot be selected with the mouse. 问题:嵌入子窗体后,无法用鼠标选择子窗体中的TextBox

Can anyone help? 有人可以帮忙吗?

I Googled the problem. 我用Google搜索了问题。 From my research I concluded that it's not a good idea to embed a Form within a Panel . 根据我的研究,我得出结论,将Form嵌入Panel并不是一个好主意。 I took another approach and have now made the child Form as an MDI child. 我采用了另一种方法,现在将子Form作为MDIForm

You need to setup the parent of the Form before calling .Show() 您需要在调用.Show()之前设置Form的父级。

form.Parent = this; form.Parent = this;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM