tags:

views:

497

answers:

1

When you use a Windows Forms TextBox, the default number of tab stops (spaces) is 8. How do you modify this?

+3  A: 

First add the following namespace

using System.Runtime.InteropServices;

Then add the following after the class declaration:

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);

Then add the following to the Form_Load event:

// define value of the Tab indent 
int[] stops = {16}; 
// change the indent 
SendMessage(this.textBox1.Handle, EM_SETTABSTOPS, 1, stops);
Omar Shahine