This project is read-only.

Syntax highlighting after file load

Aug 4, 2010 at 8:23 PM
Edited Aug 5, 2010 at 10:01 PM

When I load in a text file using ScintillaNet.Text = strMyFile, the text is not highlighted unless I go and manually enter a character on the first line to trigger the update. How do I get the text to be formatted with my assigned styles programmatically after a new file is loaded in?

I am using the DockPanel suite and have the scintilla control added to a DockContent control. I have noticed that this problem only occurs if I show the dockcontent control like this vDockConent.Show(vDockPanel) with the DockPanel as the parent. If I call Show with the form being the owner vDockContent.Show(Me) then the syntax highlighting takes effect immediately.

Does that mean that the style requires update message not being directed to the right windows message handler?

Thanks for any suggestions you can give.

Aug 6, 2010 at 7:13 PM

After recoding the application in C# the problem went away. Does this mead that Scintilla or DockPanel have a compatibility problem with VB.NET? Has anyone else tried using the two in a VB.NET application?  I've tried to see If I have some small difference between the two, but so far I don't see one. I used a code converter to convert most of the code, so it shouldn't be too different.

Aug 10, 2010 at 2:27 PM
I'm not sure what was the source of the problem, but I re-coded the app AGAIN in VB.NET, and the problem did not show up this time.
Aug 10, 2010 at 6:08 PM

huh. I don't suppose you still have the old source?

Aug 10, 2010 at 7:22 PM
Edited Aug 10, 2010 at 7:23 PM

It's too much to inline. I'm guessing something in one of the .Designer files got screwed up. The project defaulted to NET 4 (I'm using Visual Studio 2010), and after doing some of the initial form layout, I changed it to a NET 2.0 project so I wouldn't have to deal with any issues that could crop up by recompiling ScintillaNET and the DockPanel code for NET 4. The switchover might have left something in the file that shouldn't have been there.

Aug 17, 2010 at 11:45 AM
Edited Aug 17, 2010 at 2:58 PM

I'm getting a similar problem as described by rspyke.

I create the Scintilla control programatically, load in the text via ScintillaNet.Text = strMyFile and then i set the ConfigurationManager.Language to "html".

At this point I'd expect that if I did a ScintillaNet.Update() the control would now realise that it should colourise the control as per the "html" language I specified. Whether this should happen - I dont know but I'd expect at least that the ScintillaNet.StyleChanged event be triggered.

This doesn't happen. What happens if that when I show the Form, to which the Scintilla component is a child using the Form.ShowDialog() method, the form shows and then triggers the ScintillaNet.StyleChanged and updates the colour syntax.

What I'm trying to do(my end goal) is to determine if a word in the text is a comment or not: What I'd really like to do is load in the text, colourise it, and then search for a word and then see if that word is a comment. This should all happen before the Form is shown. The only way I can see if a word (represented  as a Scintialla.Range) is a comment is to ask scintilla via

string style = scintilla.Styles.GetStyleNameAt(rr.Start);

where rr represents the word that I'm querying to see if its styled as a comment. But because it seems that the style for the 'html' is not applied yet, the style variable always contains 'HTML.DEFAULT' but not 'HTML.COMMENT' which the word actually is.

I'm think there is a problem as rspkye suggested with  "the style requires update message not being directed to the right windows message handler?" 


let me know if i need to clarify(I've been looking at this for a day now so my wording/explanation could be very all-over-the-place (pretty much like my brain right now)) but hopefully you get what I'm trying to say :-)



Aug 17, 2010 at 3:02 PM
Edited Aug 20, 2010 at 5:24 PM

Well, I found a work around for it. it was to just call Form.ShowDialog() instead of Form.Show(). All this means is that when I'm call it, it lets the code continue and not block, and because the form is shown, the style gets applied, and i can manipulate the scintilla object and interrogate - while the control is being shown to the user.

Maybe this helps someone? Well, I hope so anyway.

Aug 20, 2010 at 12:05 PM
Edited Aug 20, 2010 at 5:23 PM

Found a better solution.

Just call:


right after you set the text of the scintilla control and set its language.



Dec 2, 2011 at 8:38 AM

Im not too sure, as i have the same issue as above, using and Scintilla

I tried framework 2.0 as well

Here is my simple code to load F:ocls.vb into a scintilla box.

First button to load code into scintilla1

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oFileName As String = "F:\ocls.vb"
        Dim TextLine As String = ""
        If System.IO.File.Exists(oFileName) = True Then
            Dim objReader As New System.IO.StreamReader(oFileName)
            Do While objReader.Peek() <> -1
                TextLine += objReader.ReadLine() & vbNewLine
            Scintilla1.Text = TextLine
        End If
    End Sub

Second button to set configuration manager and configure and set line width

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Scintilla1.ConfigurationManager.Language = "HTML" Scintilla1.ConfigurationManager.Configure() Scintilla1.Margins(0).Width = 50 End Sub

       unfortunately, it does not change the coloring of the code.

I how ever can see the format (style) of the text change but no syntax highlighting.

Jun 24, 2012 at 8:51 AM

As stumathews pointed out calling the Lexing.Colorize() will get highlighting.  However, my testing reveals that I need to call it after I show the docking panel.