110,534
社区成员
发帖
与我相关
我的任务
分享
private MainForm mf = new MainForm();
private void button1_Click(object sender, EventArgs e)
{
String searchString = this.textBox1.Text;
int index = mf.textBox1.Text.IndexOf(searchString);
if (index != -1)
{
mf.textBox1.Select(index, searchString.Length);
}
}
namespace testDemo
{
public partial class SearchForm : Form
{
public SearchForm()
{
InitializeComponent();
}
private MainForm mf = new MainForm();
private void button1_Click(object sender, EventArgs e)
{
String searchString = this.textBox1.Text;
int index = mf.textBox1.Text.IndexOf(searchString);
if (index != -1)
{
mf.textBox1.Select(index, searchString.Length);
}
}
}
}
{
public partial class Form1 : Form
{
public Form1() {
InitializeComponent();
}
private TextBox tBox;
public TextBox TBox {
get { return textBox1; }
set { textBox1 = value; }
}
private void button1_Click(object sender, EventArgs e) {
new Form2(this).Show();
}
}
}
{
public partial class Form2 : Form
{
Form1 F1;
public Form2(Form1 f) {
InitializeComponent();
F1 = f;
}
private void Form2_Load(object sender, EventArgs e) {
this.TopMost = true;
}
private void button1_Click(object sender, EventArgs e) {
F1.TBox.Select(1,2);
F1.TBox.Focus();
}
}
MainForm显示的时候:
new SearchForm().Show(this);
同时记得把TextBox1的访问级别改为public!
SearchForm:
private void button1_Click(object sender, EventArgs e)
{
String searchString = this.textBox1.Text;
int index = (this.Owner as MainForm).textBox1.Text.IndexOf(searchString);
if (index != -1)
{
(this.Owner as MainForm).textBox1.Select(index, searchString.Length);
}
}
private void Form2_Load(object sender, EventArgs e) {
pictureBox1.BackColor = Color.Red;
//timer1.Interval = 1;
//timer1.Enabled = true;
//SetWindowLong((IntPtr)0x000506AE, GWL_EXISTYLE, WS_EX_TOOLWINDOW);
this.TopMost = true;
}
private void button1_Click(object sender, EventArgs e) {
//F1.Btn.Focus();
F1.TBox.Select(1,2);
F1.TBox.Focus();
//new Thread(new ThreadStart(MovePic)).Start();
}
// SearchForm.cs
using System.Text;
using System.Windows.Forms;
namespace testDemo
{
public partial class SearchForm : Form
{
public SearchForm()
{
InitializeComponent();
}
private MainForm mf = new MainForm();
private void button1_Click(object sender, EventArgs e)
{
String searchString = this.textBox1.Text;
int index = mf.textBox1.Text.IndexOf(searchString);
if (index != -1)
{
mf.textBox1.Select(index, searchString.Length);
}
}
}
}