TextBox with vertical scrollbar on the left side

后端 未结 2 1978
别跟我提以往
别跟我提以往 2021-01-07 04:56

I\'m developing a Windows Forms application in C#, which has a multiline TextBox control on a form.

Due to specific (irrelevant) reasons, this TextBox needs a vertic

相关标签:
2条回答
  • 2021-01-07 05:28

    I took some of the example code from Rachel Gallen's link and made this version of the TextBox:

    public class TextBoxWithScrollLeft : TextBox {
      private const int GWL_EXSTYLE = -20;
      private const int WS_EX_LEFTSCROLLBAR = 16384;
    
      [DllImport("user32", CharSet = CharSet.Auto)]
      public extern static int GetWindowLong(IntPtr hWnd, int nIndex);
    
      [DllImport("user32")]
      public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    
      protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        int style = GetWindowLong(Handle, GWL_EXSTYLE);
        style = style | WS_EX_LEFTSCROLLBAR;
        SetWindowLong(Handle, GWL_EXSTYLE, style);
      }
    }
    

    I've never done it before, but the results seem to have worked:

    enter image description here

    0 讨论(0)
  • 2021-01-07 05:49

    By setting the RightToLeft property true. But it said the content would also be from right to left, so I don't know if that would solve your problem...But that's a way to set the scrollbar on the left hand side.

    http://bytes.com/topic/c-sharp/answers/255138-scrollbar-position

    0 讨论(0)
提交回复
热议问题