M
mj2736
I need to write a function that will set the width of tabs in a
multiline textbox windows control to a specified number of characters.
Here is the code I've tried; it is changing the tab size, but not to
the size I'm expecting. Am I going about this the wrong way? Thanks.
private const int EM_SETTABSTOPS = 0x00CB;
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam,
int[] lParam);
public static void SetTabWidth(TextBox textbox, int tabWidth)
{
Graphics graphics = textbox.CreateGraphics();
int characterWidth = (int) graphics.MeasureString("M",
textbox.Font).Width;
SendMessage(textbox.Handle, EM_SETTABSTOPS, 1, new int[] { tabWidth
* characterWidth });
}
multiline textbox windows control to a specified number of characters.
Here is the code I've tried; it is changing the tab size, but not to
the size I'm expecting. Am I going about this the wrong way? Thanks.
private const int EM_SETTABSTOPS = 0x00CB;
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam,
int[] lParam);
public static void SetTabWidth(TextBox textbox, int tabWidth)
{
Graphics graphics = textbox.CreateGraphics();
int characterWidth = (int) graphics.MeasureString("M",
textbox.Font).Width;
SendMessage(textbox.Handle, EM_SETTABSTOPS, 1, new int[] { tabWidth
* characterWidth });
}