使用 C#,如何在多行文本框中设置制表符位置?

发布于 2024-08-17 10:08:41 字数 45 浏览 3 评论 0原文

是否有一种优雅的方法可以在 C# 的多行文本框中设置自定义选项卡大小/位置?

Is there a graceful way to set custom tab sizes/positions in a multiline textbox in C#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2024-08-24 10:08:41

您需要发送 EM_SETTABSTOPS 消息,例如这:

static class NativeMethods {
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref int lParam);
}
static void SetTabs(TextBox box) {
    //EM_SETTABSTOPS - http://msdn.microsoft.com/en-us/library/bb761663%28VS.85%29.aspx
    int lParam = 16;  //Set tab size to 4 spaces
    NativeMethods.SendMessage(box.Handle, 0x00CB, new IntPtr(1), ref lParam);
    box.Invalidate();
}

You need to send the EM_SETTABSTOPS message, like this:

static class NativeMethods {
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref int lParam);
}
static void SetTabs(TextBox box) {
    //EM_SETTABSTOPS - http://msdn.microsoft.com/en-us/library/bb761663%28VS.85%29.aspx
    int lParam = 16;  //Set tab size to 4 spaces
    NativeMethods.SendMessage(box.Handle, 0x00CB, new IntPtr(1), ref lParam);
    box.Invalidate();
}
想挽留 2024-08-24 10:08:41

除了 vb 2013 之外,微软的友好人员已经决定您不再需要 Windows 句柄,并且您无法再获取它。

Apart from by vb 2013 the friendly people at microsoft have decided you no longer need the windows handle and you can no longer get at it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文