Answer the question
In order to leave comments, you need to log in
C# Windows Forms. Passing data between forms, how?
There are two forms, the first form is a text editor, and the second is its child form, which displays the search for given words in a text editor. I was able to do a search on one form, they said to do it on different ones, I can’t, I climbed so many forums, nothing works.
Here is the code if you do everything in one form:
string find = textBox2.Text;
if (richTextBox1.Text.Contains(find))
{
int i = 0;
while (i <= richTextBox1.Text.Length - find.Length)
{
i = richTextBox1.Text.IndexOf(find, i);
if (i < 0) break;
richTextBox1.SelectionStart = i;
richTextBox1.SelectionLength = find.Length;
richTextBox1.SelectionColor = Color.Blue;
i += find.Length;
}
}
else
{
// Окно сообщения будет отображаться, если введенное слово не найдено
MessageBox.Show("Не найдено ни одного соответствия результатов");
}
Answer the question
In order to leave comments, you need to log in
It looks like you need to do the following:
//событие для открытия новой формы
private void searchButton_click(object sender, EventArgs args){
using(var searchForm = new SearchForm()){
//передаем все что нужно на новую форму
searchForm.Text = richTextBox1.Text;
//показываем форму
searchForm.ShowDialog();
}
}
public class SearchForm : Form{
public string Text {get;set;}
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question