I am trying to create a Find function in a richTextBox object,
So... the child form is the find form,
and the parent form is the richTextBox's form, and i want to transfer a simple integer from the child to the parent, is it possible anyhow...?
Form1.cs's event - when clicking on the find option in the main form
private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
string textBlock = richTextBox1.Text;
Form2 f = new Form2(textBlock);
f.Show();
{
richTextBox1.Focus();
richTextBox1.Select(f.getLocation(), f.getEndLocation());
}
}
Form2.cs's event-when clicking on the find button after you wrote the keyword
private void find_btn_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length == 0) { }
else
if (this.textBlock.Length == 0)
{ MessageBox.Show("Cannot find '" + textBox1.Text + "'"); }
else
{
Boolean flag = false;
int i;
string[] Arr = textBox1.Text.Split('\n');
for (i = 0; (i < Arr.Length && !flag); i++)
{
flag = (findInContext(Arr[i]));
}
if (flag)
{
MessageBox.Show("The item was found on line " + i);
this.location = this.textBlock.IndexOf(textBox1.Text);
this.endLocation = this.location + textBox1.Text.Length;
}
else
MessageBox.Show("Cannot find '" + textBox1.Text + "'");
}
}
By the way - if you have any better algorithms for solving this problem- i'll be grateful if you post them...