Using C #, how to set tab positions in a multi-line text box?

Is there an elegant way to set custom tab / position sizes in a multi-line text box in C #?

+5
source share
2 answers

You need to send an EM_SETTABSTOPS message , for example:

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();
}
+10
source

In addition to vb 2013, the friendly people at Microsoft decided that you no longer needed a window handle and you could no longer use it.

0
source

All Articles