Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:39:48+00:00 2026-06-01T22:39:48+00:00

At the moment I’m working on a simple syntax highlighter and I have couple

  • 0

At the moment I’m working on a simple syntax highlighter and I have couple of problems. Could you help me out?

I have a class library with a component class in it. Everything is in VB.NET. It’s only one file so you can see it here https://gist.github.com/2366507 . On line 92, there is the OnTextChanged Sub. I was thinking about adding ProcessAllLines() (as on line 128) to the end of that Sub, and it worked. However when I was typing in code to the RichTextBox (source which I used is here https://gist.github.com/2366526) after each text change it was checking and processing ALL the lines. So I deleted ProcessAllLines() in the OnTextChanged Sub.

I’m thinking about running ProcessAllLines() when the user pastes something to the SyntaksRichTextBox. However I do not know how to do that. I know that it should be something like:

If [CTRL Pressed] And [V Pressed] Then
ProcessAllLines()
End If

I also want it to be in the class library, not the application (Syntaks Demo). Could you help me out here? Thanks.

Rafal Chmiel, @RafalChmiel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:39:50+00:00Added an answer on June 1, 2026 at 10:39 pm

    Naïve detection

    First solution you may think about is to detect the WM_PASTE message overriding the WndProc but unfortunately the control doesn’t send that message to itself when it performs a paste operation.

    Detecting keyboard events (you have to override the OnKeyDown function) and checking if the key combinations (CTRL+V and SHIFT+INS) is the one to paste text you may solve this.

    Protected Sub OnKeyDown(ByVal e As KeyEventArgs)
        Dim ctrlV As Boolean = e.Modifiers = Keys.Control && e.KeyCode = Keys.V
        Dim shiftIns As Boolean = e.Modifiers = Keys.Shift && e.KeyCode = Keys.Insert
    
        If ctrlV Or shiftIns Then
            ProcessAllLines
        End If
    End Sub
    

    It works well but you can’t catch the paste operation made using the mouse (right click to open the context menu) and the paste operations made via drag & drop. If you do not need them you can use this solution (at least it’s simply and straightforward).

    Better detection

    Assumption: when user types inside the RichTextBox he inserts one character per time. How can you use this? Well, when you detect a bigger change you detected a paste operation because user can’t type more than once character per time (this isn’t always true because of Unicode surrogates but it’s not a problem in this case).

    It doesn’t work well with every IME (I didn’t try with far east languages, for example) and with Unicode surrogates but for western languages it’s OK (anyway even when it doesn’t work you’ll simply reprocess all lines). Also read this post and this post for more details about Unicode and this (twin) answer for C# version.

    Dim _previousLength As Int32 = 0
    
    Protected Sub richTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
       Dim currentLength As Int32 = richTextBox.Text.Length
       If Math.Abs(currentLength - _previousLength) > 1 Then
          ProcessAllLines
       End If
    
       _previousLength = currentLength
    End Sub
    

    Perfect solution

    The perfect solution of course exists (on Windows 8 or higher), the native rich edit control sends a EN_CLIPFORMAT notification message. It’s intended to notify a rich edit control’s parent window that a paste occurred with a particular clipboard format. You can then override the WndProc of its parent to detect the WM_NOTIFY message for this notification. Anyway it’s not few lines of code, check this link on MSDN for details: http://msdn.microsoft.com/en-us/library/windows/desktop/hh768385(v=vs.85).aspx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I am working on creating a small library for common data
At the moment I have the following Command class: Public Class SubscribeCommand Implements ICommand
So at the moment I have a simple reminder app that you enter some
At the moment I have a class that requires information from another class, but
At the moment I have a jQuery do a POST to a Controller which
For the moment we're still working with the 2.0 framework and and although 2.0
Im having a moment, what i want to do is really simple and i
Imagine for a moment that I have a system that allows users to take
At the moment I have about 2000 trades which are priced using excel. I
at the moment i have this <div id=beau> <div> <input type=text id=lun name=lun size=24

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.