简体   繁体   English

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

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

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. 我正在为旧的袖珍PC编写代码编辑器程序,并且希望能够在多行文本框中更改\\t字符的大小。

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. 我已经寻找了很长时间,我发现了这个EM_SETTABSTOPS ,我不确定如何使用它,但我认为这是我需要使用的。 Is this even possible to do? 这有可能吗?

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. 然后,在InitializeComponents()之后,使用多行文本框调用该函数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio 2010中停止自动轮廓扩展? - How do I stop Auto Outline Expansion in Visual Studio 2010? 我如何阻止 Visual Studio 2017 在保存时构建 - How do i stop visual studio 2017 from building on save 我如何在 Visual Studio C# 中的 TextBox 中获取值,而不删除 TextBox 上已有的信息 - How do i get values into a TextBox in Visual studio C# without the information already on the TextBox gets erased 如何在Visual Studio IDE中更改某些语法颜色 - How do I change some of the syntax colors in the Visual Studio IDE 如何更改Visual Studio集成包(VSPackage)上的图标? - How do I change icon on a Visual Studio Integration Package (VSPackage)? 如何在 Visual Studio 2019 中更改 C# 版本 - How do I change the C# version in Visual Studio 2019 如何在Visual Studio建模项目上更改目标框架? - How do I change the Target Framework on a Visual Studio Modeling Project? 如何在Visual Studio的Windows Azure上更改列类型? - How do I change a column type on Windows Azure on Visual Studio? 如何在 Visual Studio C# 中制作一个将特定文本插入文本框中的按钮? - How do i make a button that inserts A Certain text into a textbox in Visual Studio C#? 如何使用OleDb将Visual Studio c#中MS-Access的值插入到textBox中? - how do I insert into a textBox a value from MS-Access in visual studio c# using OleDb?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM