如何在visual studio中更改文本框的制表位长度?

时间:2015-12-26 03:36:03

标签: c# visual-studio visual-studio-2008 windows-mobile pocketpc

我正在为我的旧掌上电脑制作代码编辑器程序,我希望能够在多行文本框中更改\t字符的大小。

我已经找了很长时间,我发现这个EM_SETTABSTOPS我不完全确定如何使用它,但我认为这是我需要使用的。这甚至可以吗?

1 个答案:

答案 0 :(得分:1)

在表单类代码中:

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

然后添加一个函数

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

然后,在InitializeComponents()之后,使用多行文本框调用该函数。

来源:http://www.pinvoke.net/default.aspx/user32.sendmessage