Wie man eine Kontrollmethode von einem anderen Thread aufruft
Ich möchte anrufenRichTextBox.Find()
von einem anderen Thread. Wie kann ich das machen? DasRichTextBox
befindet sich in einemUserControl
, das ich in meinem Formular verwende. Ich möchte es von einem anderen Thread aktualisieren. Ich konnte seine Eigenschaften mit @ ändeInvoke
. Aber kann nicht herausfinden, wie man @ anru_ucResultRich.rchResult.Find(word, startIndex, RichTextBoxFinds.None);
aus meinem Thread.
Thread thread=new Thread(thrHighlight);
thread.Start(e.RowIndex);
private void ThrHighlight(object obj)
{
string[] words = ucSearchControls.rdbExact.Checked
? new string[] { ucSearchControls.txtSearch.Text.Trim() }
: ucSearchControls.txtSearch.Text.Split(' ');
foreach (string word in words)
{
int startIndex = 0;
while (startIndex < _ucResultRich.rchResult.TextLength)
{
int wordStartIndex = _ucResultRich.rchResult.Find(word, startIndex, RichTextBoxFinds.None);
if (wordStartIndex != -1)
{
_ucResultRich.rchResult.SelectionStart = wordStartIndex;
_ucResultRich.rchResult.SelectionLength = word.Length;
_ucResultRich.rchResult.SelectionBackColor = Color.Yellow;
}
else
break;
startIndex += wordStartIndex + word.Length;
}
}
}
Wie kann ich das machen
P.S: Dies ist das Follow-up zumeine erste Frage und zu den @ varocarbas Kommentaren dort