[英]Cannot use mouse to select text of a text box when the text box is embedded in a SplitContainer
I have a form contains a splitContainer. 我有一个包含splitContainer的表单。 On the Panel2 of the splitContainer, I added another form, called form2.
在splitContainer的Panel2上,我添加了另一个名为form2的表单。 In form2 I have a text Box.
在form2中我有一个文本框。
I can edit the textbox, I mean I can type on the text box. 我可以编辑文本框,我的意思是我可以在文本框中输入。 However, I cannot select text in the textbox using Mouse.
但是,我无法使用鼠标在文本框中选择文本。 Here is my Code.
这是我的代码。
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.textBox1 = new System.Windows.Forms.TextBox();
this.form2 = new TestTextBox.Form2();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.textBox1);
//
// splitContainer1.Panel2
//
this.form2.TopLevel = false;
this.splitContainer1.Panel2.Controls.Add(this.form2);
this.splitContainer1.Size = new System.Drawing.Size(812, 347);
this.splitContainer1.SplitterDistance = 438;
this.splitContainer1.TabIndex = 0;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(94, 110);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(213, 20);
this.textBox1.TabIndex = 0;
//
// form2
//
this.form2.ClientSize = new System.Drawing.Size(362, 313);
this.form2.Dock = System.Windows.Forms.DockStyle.Fill;
this.form2.Location = new System.Drawing.Point(0, 0);
this.form2.Name = "form2";
this.form2.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.form2.Text = "Form2";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(812, 347);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "Form1";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
form2 have a textBox. form2有一个textBox。 and I cannot select text of this textbox using mouse.
我无法使用鼠标选择此文本框的文本。 Anyone who knows this problem, please help me!
谁知道这个问题,请帮帮我!
On the Panel2 of the splitContainer, I added another form
在splitContainer的Panel2上,我添加了另一个表单
This is not the way a split container is supposed to be used. 这不是应该使用拆分容器的方式。 You can add a
panel
to the panel2
, not a Form
! 您可以将
panel
添加到panel
panel2
,而不是Form
!
If you have to stick to using a form inside a panel for some reason, try to set the forms .toplevel to false, does it change anything? 如果由于某种原因必须坚持在面板内使用表单,请尝试将表单.toplevel设置为false,它是否会更改任何内容?
If you really dont need to use a form, then convert the form to a usercontrol instead and add the usercontrol to the panel. 如果您确实不需要使用表单,则将表单转换为usercontrol,然后将usercontrol添加到面板中。
You will have focus problem when using forms this way. 以这种方式使用表单时会出现焦点问题。 I dont think you even get Form.Focus() and maybe some other events this way...
我不认为你甚至得到Form.Focus()和其他一些事件......
Maybe you will be helped by the example here, scroll down to: Add Forms as usercontrols 也许你会得到这个例子的帮助,向下滚动到: 添加表格作为usercontrols
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.