How do I change the tab stop length for a textbox in visual studio?

878 Views Asked by At

I am making a code editor program for an old pocket PC I have, and I want to be able to change the size of the \t character in a multi-line textbox.

I have looked for a really long time and I found this EM_SETTABSTOPS which I am not entirely sure how to use that but I think it is what I need to use. Is this even possible to do?

1

There are 1 best solutions below

0
josef On

In your form class code:

private const UInt32 EM_SETTABSTOPS = 0x00CB;
private const int unitsPerCharacter = 4;

[DllImport("CoreDll.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref IntPtr lParam);

then add a function

public static void SetTextBoxTabStopLength(TextBox tb, int tabSizeInCharacters)
{
    // 1 means all tab stops are the the same length
    // This means lParam must point to a single integer that contains the desired tab length
    const uint regularLength = 1;

    // A dialog unit is 1/4 of the average character width
    int length = tabSizeInCharacters * unitsPerCharacter;

    // Pass the length pointer by reference, essentially passing a pointer to the desired length
    IntPtr lengthPointer = new IntPtr(length);
    SendMessage(tb.Handle, EM_SETTABSTOPS, (IntPtr)regularLength, ref lengthPointer);
}

Then, after InitializeComponents(), call the function with your multiline textbox.

Source: http://www.pinvoke.net/default.aspx/user32.sendmessage