首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在visual studio中更改文本框的制表位长度?

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

Stack Overflow用户
提问于 2015-12-26 11:36:03
回答 1查看 657关注 0票数 1

我正在为我有一个旧的掌上电脑做一个代码编辑器程序,我想能够改变一个多行文本框中的\t字符的大小。

我已经找了很长时间了,我找到了这个EM_SETTABSTOPS,我不完全确定如何使用它,但我认为它是我需要使用的。这有可能做到吗?

EN

Stack Overflow用户

发布于 2015-12-27 14:38:48

在窗体类代码中:

代码语言:javascript
复制
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);

然后添加一个函数

代码语言:javascript
复制
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

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34468274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档