Using C#, how do I set tab positions in a multiline textbox?
Is there a graceful way to set custom tab sizes/positions in a multiline textbox in C#?开发者_开发问答
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();
}
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.
精彩评论