D
D
Dmitry Korolev2016-09-23 23:51:27
C++ / C#
Dmitry Korolev, 2016-09-23 23:51:27

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

2 answer(s)
D
Dmitry Korolev, 2016-09-29
@adressmoeistranici

bf98cf238ea443ef88d33e92205b4e1a.pnghe does not see the void, but he is public

A
Alexander Evseev, 2016-09-29
@alex1t

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 question

Ask a Question

731 491 924 answers to any question