<legend id='KEizx'><style id='KEizx'><dir id='KEizx'><q id='KEizx'></q></dir></style></legend>
    <i id='KEizx'><tr id='KEizx'><dt id='KEizx'><q id='KEizx'><span id='KEizx'><b id='KEizx'><form id='KEizx'><ins id='KEizx'></ins><ul id='KEizx'></ul><sub id='KEizx'></sub></form><legend id='KEizx'></legend><bdo id='KEizx'><pre id='KEizx'><center id='KEizx'></center></pre></bdo></b><th id='KEizx'></th></span></q></dt></tr></i><div id='KEizx'><tfoot id='KEizx'></tfoot><dl id='KEizx'><fieldset id='KEizx'></fieldset></dl></div>
  • <tfoot id='KEizx'></tfoot>

      • <bdo id='KEizx'></bdo><ul id='KEizx'></ul>
    1. <small id='KEizx'></small><noframes id='KEizx'>

        如何在 Windows 窗体 TextBox 控件中设置 TAB 宽度?

        时间:2023-06-09
        <tfoot id='DvE8h'></tfoot>
            1. <small id='DvE8h'></small><noframes id='DvE8h'>

            2. <legend id='DvE8h'><style id='DvE8h'><dir id='DvE8h'><q id='DvE8h'></q></dir></style></legend>

                <tbody id='DvE8h'></tbody>

                  <bdo id='DvE8h'></bdo><ul id='DvE8h'></ul>
                  <i id='DvE8h'><tr id='DvE8h'><dt id='DvE8h'><q id='DvE8h'><span id='DvE8h'><b id='DvE8h'><form id='DvE8h'><ins id='DvE8h'></ins><ul id='DvE8h'></ul><sub id='DvE8h'></sub></form><legend id='DvE8h'></legend><bdo id='DvE8h'><pre id='DvE8h'><center id='DvE8h'></center></pre></bdo></b><th id='DvE8h'></th></span></q></dt></tr></i><div id='DvE8h'><tfoot id='DvE8h'></tfoot><dl id='DvE8h'><fieldset id='DvE8h'></fieldset></dl></div>
                • 本文介绍了如何在 Windows 窗体 TextBox 控件中设置 TAB 宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  给定一个带有 MultiLine = trueAcceptsTab == true 的 WinForms TextBox 控件,如何设置显示的制表符的宽度?

                  Given a WinForms TextBox control with MultiLine = true and AcceptsTab == true, how can I set the width of the tab character displayed?

                  我想将其用作插件的快速而肮脏的脚本输入框.真的完全不需要花哨,但如果标签不显示为 8 个字符宽就好了……

                  I want to use this as a quick and dirty script input box for a plugin. It really doesn't need to be fancy at all, but it would be nice if tabs were not displayed as 8 characters wide...

                  推荐答案

                  我认为将 EM_SETTABSTOPS 消息发送到 TextBox 会起作用.

                  I think sending the EM_SETTABSTOPS message to the TextBox will work.

                  // set tab stops to a width of 4
                  private const int EM_SETTABSTOPS = 0x00CB;
                  
                  [DllImport("User32.dll", CharSet = CharSet.Auto)]
                  public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam);
                  
                  public static void SetTabWidth(TextBox textbox, int tabWidth)
                  {
                      Graphics graphics = textbox.CreateGraphics();
                      var characterWidth = (int)graphics.MeasureString("M", textbox.Font).Width;
                      SendMessage
                          ( textbox.Handle
                          , EM_SETTABSTOPS
                          , 1
                          , new int[] { tabWidth * characterWidth }
                          );
                  }
                  

                  这可以在 Form 的构造函数中调用,但要注意:确保首先运行 InitializeComponents.

                  This can be called in the constructor of your Form, but beware: Make sure InitializeComponents is run first.

                  • 链接在 MSDN
                  • 这是另一个链接

                  这篇关于如何在 Windows 窗体 TextBox 控件中设置 TAB 宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:WPF:当 TextBox 具有焦点时为 ListBox 设置 IsSelected,而不会丢失 LostFocus 上 下一篇:如何使用 C# 滚动到 WinForms TextBox 中的指定行?

                  相关文章

                  <i id='du4Js'><tr id='du4Js'><dt id='du4Js'><q id='du4Js'><span id='du4Js'><b id='du4Js'><form id='du4Js'><ins id='du4Js'></ins><ul id='du4Js'></ul><sub id='du4Js'></sub></form><legend id='du4Js'></legend><bdo id='du4Js'><pre id='du4Js'><center id='du4Js'></center></pre></bdo></b><th id='du4Js'></th></span></q></dt></tr></i><div id='du4Js'><tfoot id='du4Js'></tfoot><dl id='du4Js'><fieldset id='du4Js'></fieldset></dl></div>
                • <legend id='du4Js'><style id='du4Js'><dir id='du4Js'><q id='du4Js'></q></dir></style></legend>
                      <bdo id='du4Js'></bdo><ul id='du4Js'></ul>

                    <small id='du4Js'></small><noframes id='du4Js'>

                    1. <tfoot id='du4Js'></tfoot>