5

Is there a graceful way to set custom tab sizes/positions in a multiline textbox in C#?

Borislav Ivanov
  • 4,684
  • 3
  • 31
  • 55
Jim Fell
  • 13,750
  • 36
  • 127
  • 202

2 Answers2

10

You need to send the EM_SETTABSTOPS message, like this:

static class NativeMethods {
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref int lParam);
}
static void SetTabs(TextBox box) {
    //EM_SETTABSTOPS - http://msdn.microsoft.com/en-us/library/bb761663%28VS.85%29.aspx
    int lParam = 16;  //Set tab size to 4 spaces
    NativeMethods.SendMessage(box.Handle, 0x00CB, new IntPtr(1), ref lParam);
    box.Invalidate();
}
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Apart from by vb 2013 the friendly people at microsoft have decided you no longer need the windows handle and you can no longer get at it.

Dave
  • 11
  • 1