Using C#, how do I set tab positions in a multilin

2019-06-21 18:06发布

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

2条回答
家丑人穷心不美
2楼-- · 2019-06-21 18:45

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.

查看更多
来,给爷笑一个
3楼-- · 2019-06-21 18:51

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();
}
查看更多
登录 后发表回答