Community
    • Login

    How to use StyleSetBack properly

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    5 Posts 3 Posters 415 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Michael LeungM
      Michael Leung
      last edited by

      Hi everyone,

      I am new to programming, and I want to mess around with Notepad plugin because I use it alot in my work. I am using C# and want to change the first letter background to blue background. This is my code

        scint = new ScintillaGateway(PluginBase.GetCurrentScintilla());
          int style = 50;
          scint.StyleSetBack(style, new Colour(127, 218, 219));
          scint.StartStyling(0, 0);
          scint.SetStyling(1, style);
      

      It’s not changing any colours though, so I appreciate any insight. Thanks for all your help!

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @Michael Leung
        last edited by

        @Michael-Leung

        This looks ok to me. A similar code in python works.

        ddc1b537-ef5a-4dfe-b66d-e925d9bd3a21-image.png

        but note that it can be overlaid if your current line is the same.

        27167ef5-229d-4248-87c4-310c992388f1-image.png

        Michael LeungM 1 Reply Last reply Reply Quote 1
        • Michael LeungM
          Michael Leung @Ekopalypse
          last edited by

          @Ekopalypse Thanks for the reply. However, I tested it again but it still doesn’t work on my end. This is the full code

          using Kbg.NppPluginNET.PluginInfrastructure;
          using System;
          using System.Diagnostics;
          using System.Runtime.InteropServices;
          using System.Threading;
          using static System.Windows.Forms.VisualStyles.VisualStyleElement;
          
          namespace Kbg.NppPluginNET
          {
              class Main
              {
                  internal const string PluginName = "Test";
          
                  public static void OnNotification(ScNotification notification)
                  {
                      // This method is invoked whenever something is happening in notepad++
                      // use eg. as
                      // if (notification.Header.Code == (uint)NppMsg.NPPN_xxx)
                      // { ... }
                      // or
                      //
                      // if (notification.Header.Code == (uint)SciMsg.SCNxxx)
                      // { ... }
                  }
          
                  internal static void CommandMenuInit()
                  {
          
                      PluginBase.SetCommand(0, "Start", start);
                  }
          
                  internal static void SetToolBarIcon()
                  {
                      
                  }
          
                  internal static void PluginCleanUp()
                  {
                      
                  }
          
                  internal static void start()
                  {
          
                      int style = 50;
                      var Window = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                      Window.StyleSetBack(style, new Colour(127, 218, 219));
                      Window.StartStyling(0, 0);
                      Window.SetStyling(1, style);
                  }
          
              }
          
          }
          

          Is there any settings I have to set?

          rdipardoR 1 Reply Last reply Reply Quote 0
          • rdipardoR
            rdipardo @Michael Leung
            last edited by rdipardo

            @Michael-Leung said in How to use StyleSetBack properly:

            I tested it again but it still doesn’t work on my end.

            Like @Ekopalypse tried to explain, the style you are setting is probably hidden by the caret line background (a horizontal bar spanning the current line), which is opaque by default.

            Your method could try moving the caret to the next line (assuming there’s at least two lines in the document), like this:

            + private static void GoToNextLine()
            + {
            +   IntPtr lineEndCurrent, lineStartNext;
            +   var hwnd = PluginBase.GetCurrentScintilla();
            +   var editor = new ScintillaGateway(hwnd);
            +   lineEndCurrent = Win32.SendMessage(hwnd, SciMsg.SCI_GETLINEENDPOSITION, editor.GetCurrentLineNumber(), 0);
            +   lineStartNext = Win32.SendMessage(hwnd, SciMsg.SCI_POSITIONAFTER, lineEndCurrent, 0);
            +   editor.SetEmptySelection((int)lineStartNext);
            + }
            
              internal static void start()
              {
            
                int style = 50;
                var Window = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                Window.StyleSetBack(style, new Colour(127, 218, 219));
                Window.StartStyling(0, 0);
                Window.SetStyling(1, style);
            +   GoToNextLine();
              }
            

            StyleSetBack

            Michael LeungM 1 Reply Last reply Reply Quote 3
            • Michael LeungM
              Michael Leung @rdipardo
              last edited by

              @rdipardo Oh wow that worked great!

              Really appreciate the time you guys took to help me, thanks!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors