"일꾼이 일을 잘하려면 먼저 도구를 갈고 닦아야 한다." - 공자, 『논어』.
첫 장 > 프로그램 작성 > 구문 강조 표시시 RichTextBox 깜박임을 제거하는 방법은 무엇입니까?

구문 강조 표시시 RichTextBox 깜박임을 제거하는 방법은 무엇입니까?

2025-04-17에 게시되었습니다
검색:714

How to Eliminate RichTextBox Flickering During Syntax Highlighting?

RichTextBox Syntax 하이라스 강조 강조

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyRichTextBox : RichTextBox {
    public void BeginUpdate() {
        SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero);
    }
    public void EndUpdate() {
        SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero); 
        this.Invalidate();
    }
    [DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
    private const int WM_SETREDRAW = 0x0b;
}

최신 기능이 필요합니다. 솔루션

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyRichTextBox : RichTextBox {
    public void BeginUpdate() {
        SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero);
    }
    public void EndUpdate() {
        SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero); 
        this.Invalidate();
    }
    [DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
    private const int WM_SETREDRAW = 0x0b;
}
현재 솔루션에는 "wndproc"기능을 재정의하여 다시 Refaint 메시지를 가로 채고 억제하는 것이 포함됩니다. 그러나이 접근법은 제공된 RichTextBox에서 작업하는 외부 기능에 실용적이지 않습니다.

How to Eliminate RichTextBox Flickering During Syntax Highlighting?

감독을 극복하는

더 효과적인 접근 방식은 누락 된 시작 및 종말 메소드 메소드를 RichTextBox 클래스에 추가하는 것입니다. 이 메소드는 다시 페인팅을 억제하기 위해 WM_SETREDRAW 메시지를 생성합니다.

메소드 추가

다음 코드를 사용하여 새 클래스를 만듭니다. System.windows.forms 사용; system.runtime.interopservices 사용; 클래스 MyRichtextBox : RichTextBox { public void beginupdate () { sendMessage (this.handle, wm_setredraw, (intptr) 0, intptr.zero); } public void endupdate () { sendMessage (this.handle, wm_setredraw, (intptr) 1, intptr.zero); this.invalidate (); } [dllimport ( "user32.dll")] 개인 정적 외부 intptr sendmessage (intptr hwnd, int msg, intptr wp, intptr lp); 개인 const int wm_setredraw = 0x0b; }

사용법

이 방법을 사용하여 구문 하이라이트 기능 내에서 리 페인팅을 비활성화하고 활성화 할 수 있습니다. 텍스트를 업데이트하기 전후 직후.

sendMessage (this.handle, wm_setredraw, (intptr) 0, intptr.zero); // 리페인트를 비활성화합니다 // 텍스트 업데이트 sendMessage (this.handle, wm_setredraw, (intptr) 1, intptr.zero); // 다시 페인팅을 활성화합니다 this.invalidate ();

최신 튜토리얼 더>

부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.

Copyright© 2022 湘ICP备2022001581号-3