Results 1 to 4 of 4

Thread: [2005] Override WndProc

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    48

    [2005] Override WndProc

    Hello,

    I'm currently writing a syntax coloring algorithm using a RichTextBox to get familiar with VS2005 and Visual Basic .NET (I used to code in Visual Basic 6). Right now, using the TextChanged declaration of the RichTextBox, I recheck and recolor the entire line every time TextChanged is called. Perhaps not the best way, but it'll do for now. I'm open for suggestions on this!

    Anyway, what I'm trying to deal with right now is the flickering. Typing a sentence in the RTB causes a lot of flicker while the line is being recolored. I had the idea of overriding the WndProc, and stopping any WM_PAINT messages that come in while it's repainting, but it's not going very well so far. Here's what I have right now;

    Code:
        Protected Overrides Sub wndproc(ByRef m As Message)
            If (m.Msg = WM_PAINT And doNotPaint) Then
                ' ignore
            Else
                MyBase.WndProc(m)
            End If
    
        End Sub
    doNotPaint is set to true at the begging of the recoloring, and set to false again when it's finished with this. As some might see, I'm entirely new to this WndProc thing so this code is probably rubbish. It's not even attached to the RTB control in any way.

    So, could anyone give me some suggestions on this? Thanks a lot.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Override WndProc

    I'm not sure whether that theory will hold or not, but you need to override the RTB's WndProc method if it's to have a chance. That means defining your own class that inherits RichTextBox, overriding WndProc, then placing an instance of that class on your form instead of a regular RTB.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    48

    Re: [2005] Override WndProc

    Sounds good, but how would I do that? I have no idea how to create classes that inherit user controls.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Override WndProc

    There are no UserControls involved. You inherit the RichTextBox class the same way you inherit any other class. You declare a class and you add an Inherits line.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width