을 발사하지 않고, 비동기 적으로 다시 포맷하는 방법이 나는하여 RichTextBox으로 윈폼 응용 프로그램이
WinForms RichTextBox: how to perform a formatting on TextChanged?윈폼를 RichTextBox가 : TextChanged 이벤트
에 후속하고, 응용 프로그램 자동 하이라이트의 내용이 상자는 말했다. 서식이 큰 문서의 경우 10 초 이상 소요될 수 있으므로 서식있는 텍스트를 다시 서식 지정하기 위해 BackgroundWorker를 설정했습니다. 그것은 텍스트를 안내하며 이러한 일련의 수행
rtb.Select(start, length);
rtb.SelectionColor = color;
가이 일을하는 동안을, UI는 반응 남아있다.
BackgroundWorker는 TextChanged 이벤트에서 시작됩니다. 같은 : 무한 루프 :의 SelectionColor에 대한 모든 할당은 화재 TextChanged 이벤트가 발생,
private void DoBackgroundColorizing(object sender, DoWorkEventArgs e)
{
do
{
wantFormat.WaitOne();
wantFormat.Reset();
while (moreToRead())
{
rtb.Invoke(new Action<int,int,Color>(this.SetTextColor,
new object[] { start, length, color}) ;
}
} while (true);
}
private void SetTextColor(int start, int length, System.Drawing.Color color)
{
rtb.Select(start, length);
rtb.SelectionColor= color;
}
을하지만 :
private ManualResetEvent wantFormat = new ManualResetEvent(false);
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
xpathDoc = null;
nav = null;
_lastChangeInText = System.DateTime.Now;
if (this.richTextBox1.Text.Length == 0) return;
wantFormat.Set();
}
배경 작업자 방법은 다음과 같습니다.
포맷을 수행하는 BackgroundWorker에서 발생한 텍스트 변경과 외부에서 발생한 텍스트 변경을 구분하려면 어떻게합니까?
텍스트 형식 변경과 독립적으로 텍스트 내용 변경을 감지 할 수 있으면이 문제를 해결할 수도 있습니다.
내 솔루션과 의견을 통해 최종 솔루션에 대한 영감을 얻을 수있어서 기쁩니다. –
대단히 고마워, 에릭. – Cheeso
어쩌면 내 답변을 취소 할 수 있습니까? –