Answer the question
In order to leave comments, you need to log in
How to highlight text?
I call this input from another form
public void Selection()
{
if (!String.IsNullOrEmpty(rtbTextPad.Text))
{
rtbTextPad.SelectionStart = first[Textt.count];
rtbTextPad.SelectionLength = (first[Textt.count] + lengthText) - 1;
rtbTextPad.SelectionColor = Color.Red;
}
System.Console.WriteLine("selsted");
}
I call like this
private void btSearchNext_MouseUp(object sender, MouseEventArgs e)
{
fMain fMa = new fMain();
fMa.Activate();
fMa.Selection();
}
the text is not highlighted
as it is necessary to activate the RichTextBox yet?
Answer the question
In order to leave comments, you need to log in
fMain fMa = new fMain();
What is this for?
By doing this, you create a copy of your form, rather than using the one that already exists.
I add proof-of-concept:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Selection()
{
if (!String.IsNullOrEmpty(rtbTextPad.Text))
{
rtbTextPad.SelectionStart = 0;
rtbTextPad.SelectionLength = rtbTextPad.Text.Length;
rtbTextPad.SelectionColor = Color.Red;
}
System.Console.WriteLine("selected");
}
private void button1_Click(object sender, EventArgs e)
{
Selection();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question