好的,所以我有我的主要表格(Form1)和SearchReplace表格。我的SearchReplace表单包含一个文本框和一个按钮。当按下按钮时,它应该选择文本框中的任何内容Form1,但什么也不做。谁能帮我?没有给我一个错误,只是没有在运行时做任何事情。
搜索替换
public void button1_Click(object sender, EventArgs e)
{
Form1.searchT = textBox1.Text;
Form1 form1 = new Form1();
form1.searchText();
this.Close();
}
Form1 搜索文本
public void searchText() // search function
{
if (searchT != null)
{
if (textBox1.TextLength > 0)
{
if (textBox1.Text.Contains(searchT))
{
textBox1.SelectionStart = textBox1.Text.IndexOf(searchT);
textBox1.SelectionLength = searchT.Length;
}
}
}
}
searchT 是一个公共字符串,Form1因为当我以前询问将数据从一种形式传递到另一种形式时,有人告诉我直接通过Form1而不是使用form1对象更容易做到这一点。