Adjustable Line Spacing Possible?

Topics: Developer Forum, User Forum
Apr 1, 2011 at 10:07 AM
Edited Apr 1, 2011 at 10:08 AM

I am using ScintillaNet 2.2. Is it possible to adjust the spacing between lines (ending in \n)? I am creating a log viewing tool and would like to adjust this when LineWrap is enabled. Right now I am adding extra newlines to the text, but this is not a good solution since it messes up the line numbering (doubles the count basically).

Thanks for any help.

Apr 1, 2011 at 1:14 PM

I'm not sure if there's a specific value in the code that you could set that would let you do this, (there very likely is), but as an alternative, you could create a custom font with the amount of extra space you need under it, then just set it to the font it uses in the control.

Apr 1, 2011 at 1:32 PM
Edited Apr 1, 2011 at 1:33 PM

Line Heights in Scintilla are based off the largest font size in any of the styles. Offhand I don't remember how smart this is so you may have to play around to get this working the way you want. First I would try finding an unused style and setting its font size to something large. The downside to this is that the caret will fill up the entire line height which looks funny. Also you can't control vertical alignment, it will always be bottom.

Apr 2, 2011 at 12:05 AM

Thanks for the replies. As an alternative approach, is there a way to control line numbering, so it doesn't count lines with only a newline (\n) on them?

Apr 2, 2011 at 4:55 AM

Better still, use the SCI_SETEXTRAASCENT/SCI_GETEXTRAASCENT and SCI_SETEXTRADESCENT/SCI_GETEXTRADESCENT messages. They will do exactly what you're looking for. As always, sorry they're not wired into the managed wrapper already but I swear it was on my to-do list.



Apr 4, 2011 at 5:29 PM

Hi Jacob, that looks like it might do the trick. Could you point me to an example of how to set messages from C#? I did not see any reference to this in the documentation.


Apr 4, 2011 at 6:38 PM

As Jacob mentioned, these messages haven't been implemented. They weren't around when ScintillaNet 2x was originally written and it hasn't been updated to include them. You'll basically have to do the same thing that ScintillaNet does for you under the covers. The WIN32 SendMessage API function is the way ScintillaNet talks to the Native Scintilla. In ScintillaNet 2x the easiest way to invoke this is to use the INativeScintilla interface which exposes a SendMessageDirect method. First thing you need to do is look up these messages in the Scintilla documentation to understand how they work

Define your message constants. I just Googled SCI_SETEXTRAASCENT and found these values, they are probably right but I haven't tested them. To know for sure you have to look through the Scintilla source code (I think Scintilla.iface is the file)

private const uint SCI_SETEXTRAASCENT = 2525;
private const uint SCI_GETEXTRAASCENT = 2526;
private const uint SCI_SETEXTRADESCENT = 2527;
private const uint SCI_GETEXTRADESCENT = 2528;

SendMessageDirect has 18 overloads to accommodate the various Scintilla Message "signatures". Looking over the documentation I would venture to guess you want to use

int SendMessageDirect(uint msg, int wParam)

For the setters (discarding the return value) and


int SendMessageDirect(uint msg)

For the getters. Assuming you have a ScintillaNet control named "scintilla" do something like this

scintilla.NativeInterface.SendMessageDirect(SCI_SETEXTRAASCENT, 10);
int extraAscent = scintilla.NativeInterface.SendMessageDirect(SCI_GETEXTRAASCENT); // Should be 10


Apr 4, 2011 at 7:02 PM

Thanks Chris, that is very clear.

Apr 4, 2011 at 7:34 PM
Edited Apr 4, 2011 at 7:36 PM

This seems to be having no affect. My implementation:

        // ----------------------------------------------------------------------------------
        // Populate RTB with LogFile Data
        // ----------------------------------------------------------------------------------
        private void SetTextBoxContents(List<String> contents) {
            scintilla.IsReadOnly = false;

            scintilla.Text = "";

            if (contents != null) {
                String newline = "\n";
                scintilla.NativeInterface.SendMessageDirect(SCI_SETEXTRADESCENT, 0);
                if (scintilla.LineWrap.Mode == WrapMode.Word) {
                    //newline = "\n\n";
                    scintilla.NativeInterface.SendMessageDirect(SCI_SETEXTRADESCENT, 10);

                foreach (String line in contents) {
                    scintilla.AppendText(line + newline);

            scintilla.IsReadOnly = true;

            UpdateFilterResults(LogFileContents.Instance().OriginalFileContents.Count, contents.Count);
When I was testing, I also tried retrieving the value right after setting it. It was returning 0. So I must not be going about this right.
I did confirm the constants value, and they were the same as you posted.
Apr 4, 2011 at 8:20 PM

You probably have an old SciLexer.dll that doesn't support the message. I did a quick check in the Scintilla documentation but couldn't easily see which version this was introduced. If you grab the latest SciLexer.dll off of you should be good. Also I think we have newer SciLexer and SciLexer64 dlls in the 4.0 branch of ScintillaNET.

Apr 5, 2011 at 12:46 AM

Yep that was the problem. It's working now, but it's spacing every line in wrap mode, not just newlines. I'll play around and see if I can get the behavior I want. Thanks.

Apr 5, 2011 at 9:22 AM

It seems that ASCENT and DESCENT  are applied globally, and I was unable to find a way to apply them per newline (\n). So I tried out indentation on WordWrap, and it works pretty well. It's not as good as spacing, but it's better than inconsistent line numbering. If anyone has any ideas to get the line spacing to work with newlines in WordWrap mode, I'd like to try them out.

Just to be clear on what I'm after, in WordWrap mode, and single line is wrapped once it reaches the end of the viewable window. It continues wrapping until a newline is reached, and starts again with the next line. I want that next line to be spaced further down, but not the wrapped text within the same line. Even this forum does it.. newlines have a different spacing than wrapped lines :)

Thanks again for the help!

Apr 5, 2011 at 2:08 PM

Actually, using a SciLexer dll that's v2.20 or higher will stop ScintillaNet from being able to highlight it. I suspect that this is because of a difference in the way the lexers are implemented in v2.12 and below, and v2.20 and above. I am currently working to fix this issue. (I'm still trying to identify the specific changes that are causing the problems.) Also, the newest SciLexer dll's that work are in both the 2.0 and 4.0 branch. I don't think I have the custom dll that 4.0 uses in the 3.0 branch, so that might still be from a standard build.