一个窗体叫Form1(主窗体)有一个button1和一个Textbox ,有如下代码
private void button1_Click(object sender, EventArgs e)
{
Form2 F2 = new Form2();
F2.Show();
}
public void SelextText11(int start, int length)
{
textBox1.Select(start, length);
}
另一个窗体Form2只有一个按钮,有如下代码
private void button1_Click(object sender, EventArgs e)
{
frmMain f1 = new frmMain();
f1.SelextText11(3, 3);
}
为什么不能把Form1中的Textbox1中的字体选中变蓝色啊?
private void button1_Click(object sender, EventArgs e)
{
Form2 F2 = new Form2();
F2.Show();
}
public void SelextText11(int start, int length)
{
textBox1.Select(start, length);
}
另一个窗体Form2只有一个按钮,有如下代码
private void button1_Click(object sender, EventArgs e)
{
frmMain f1 = new frmMain();
f1.SelextText11(3, 3);
}
为什么不能把Form1中的Textbox1中的字体选中变蓝色啊?
名称不符
http://topic.csdn.net/u/20081128/21/1ca1b74a-4be0-4173-8b95-b99692b33041.html
public class Form2: Form
{
private Form mainForm;
public Form2(Form mainForm)
{
//
this.mainForm = mainForm;
}
// 调用f1.SelectText11()就没有问题
}
private void button1_Click(object sender, EventArgs e)
{
Form2 F2 = new Form2();
F2.Tag = this;
F2.Show();
}
public void SelextText11(int start, int length)
{
textBox1.Select(start, length);
}
另一个窗体Form2只有一个按钮,有如下代码
private void button1_Click(object sender, EventArgs e)
{
Form1 f1 = (Form1)this.Tag;
f1.SelextText11(3, 3);
} 按红字部分修改下就行了