Given a WinForms TextBox control with MultiLine = true
and AcceptsTab == true
, how can I set the width of the tab character displayed?
I wa
The example offered is incorrect.
The EM_SETTABSTOPS
message expects the tab sizes to be specified in dialog template units and not in pixels. After some digging around, it appears that a dialog template unit equals to 1/4th the average width of the window's character. So you'll need to specify 8 for 2 characters long tabs, 16 for four charachters, and so on.
So the code can be simplified as:
public static void SetTabWidth(TextBox textbox, int tabWidth)
{
SendMessage(textbox.Handle, EM_SETTABSTOPS, 1,
new int[] { tabWidth * 4 });
}