簡體   English   中英

如何在Visual Studio中更改文本框的制表位長度?

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

我正在為舊的袖珍PC編寫代碼編輯器程序,並且希望能夠在多行文本框中更改\\t字符的大小。

我已經尋找了很長時間,我發現了這個EM_SETTABSTOPS ,我不確定如何使用它,但我認為這是我需要使用的。 這有可能嗎?

在您的表單類代碼中:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM