shahine.com/omar/

homepage | Send mail to the author(s) contact

yet another Microsoft blogger

# Thursday, August 28, 2003

Changing the tab stop in a textbox

The other day I was writing an app that used a text box. However, the default number of tab spaces (amount of white space) is too large for me (set to 8 spaces).

I searched in vain for a way to do this and a fellow Microsoft co-worker showed me how.

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

 

Comments are closed.