Getting Started

Topics: User Forum
Apr 11, 2015 at 8:57 AM
Hi All

I must confess I'm having real trouble getting started with the ScintillaNET control. I'm not even going to post any code as I am nowhere near anything worthy of critique. Rather I will just explain what I want to achieve and hopefully somebody will be able to post a snippet of code in (or c# which I can convert) which will do the job and I can take it from there.

First, I want to control this with code in rather than an xml file so that it is easier to adjust dynamically. So, my wishlist is:

1) Create five keyword lists and five styles (just different colours for now). Assign one style to each keyword list so that any word in that list is styled accordingly. The comment prefix is // and comments should be in green.

2) If one of my keywords is, for instance, ScintillaNET and I just type scintillanet, it should capitalize automatically as per the keyword in the list.

3) Where I have multiple keywords beginning with the same letters, I should get a list of possible words come up, much like an enumeration in

4) Finally, it would be nice to be able to set the line number of my first line - for instance if I am using pages and I am viewing page 2 I might want to display just lines 101-200 and of course I would then want the line numbers to be 101-200 not 1-100, so I will want to set the first line to 101.

I dare say that once you know how to use Scintilla the above can all be achieved in little more than a few seconds with just a few lines of code and it will all look really obvious. So it would be fantastic if somebody could help me out here!


Apr 19, 2015 at 9:55 PM
OK so after much struggling I've managed to sort everything except item 4 above. So does anybody have any ideas how to set the first line number of a ScintillaNet control, so that the very first line number is 101, or 201 or whatever I choose?
Apr 19, 2015 at 10:45 PM
The line numbering provided by Scintilla cannot be changed. You could, however, create your own line numbers by using a text margin and setting the margin text for each line.

Apr 20, 2015 at 9:14 AM
Thanks Jacob

So I tried to add a text margin but can't get it to work. I tried:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByRef lParam As Integer) As IntPtr
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByRef lParam As String) As IntPtr

Public Const SCI_SETMARGINTYPEN = 2240
Public Const SC_MARGIN_SYMBOL = 0
Public Const SC_MARGIN_NUMBER = 1
Public Const SC_MARGIN_TEXT = 4
Public Const SC_MARGIN_RTEXT = 5

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    SendMessage(sc1.Handle, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER)
    SendMessage(sc1.Handle, SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL)
    SendMessage(sc1.Handle, SCI_SETMARGINTYPEN, 2, SC_MARGIN_TEXT)
    SendMessage(sc1.Handle, SCI_SETMARGINTYPEN, 3, SC_MARGIN_RTEXT)
    SendMessage(sc1.Handle, SCI_MARGINSETTEXT, 1, "101")
    SendMessage(sc1.Handle, SCI_MARGINSETTEXT, 2, "102")
    SendMessage(sc1.Handle, SCI_MARGINSETTEXT, 3, "103")

End Sub
but this completely obliterates everything in the margins when I click Button1, including the original line number even if I only send the first SendMessage.

What am I doing wrong here?

Thanks again

Apr 23, 2015 at 4:54 PM

Your question comes at an interesting time if the development life of ScintillaNET. The 2.x version hosted here at CodePlex is no longer being maintained and I'm moving development of the next version to GitHub. The repository is here:

In the project documentation you'll find an example for "custom line numbers" which I've added specifically to answer your question. The principles are applicable to the legacy 2.x version hosted here at CodePlex but I would urge you to also consider upgrading to the new codebase.

Apr 24, 2015 at 9:35 PM
Thank you Jacob, this looks like it has all the functions and documentation I wanted to see. But there is a problem and maybe I'm missing something obvious, but how do I get this new control into my project? I tried adding it to the toolbox as per the original ScintillaNet method, but it just said that it "is not a Microsoft .net module" and wouldn't let me add it. So I tried adding the dll as a reference, no joy there either. I'm running Windows XP, would that make a difference?

Once I can get this new control into my project I should be OK!

Thanks again

Apr 24, 2015 at 11:07 PM

WindowsXP? Yikes! I have no idea if that will work or not. I certainly haven't done any testing on XP to make sure...

Are you sure you're adding the right DLL? To get a build from GitHub you should check out the releases:

The result of either building yourself, using NuGet, or downloading a precompiled zip package will be a ScintillaNET.dll. You should be able to add that to the toolbox or as a reference.

Since this discussion is related to the new version of ScintillaNET you should PM me any additional questions or move the discussion to GitHub.