如何修改TextBox控件的制表位
时间:2020-03-05 18:49:48 来源:igfitidea点击:
当我们使用Windows窗体文本框时,默认的制表位(空格)数为8. 如何修改此设置?
解决方案
回答
首先添加以下名称空间
using System.Runtime.InteropServices;
然后在类声明之后添加以下内容:
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);
然后将以下内容添加到Form_Load事件:
// define value of the Tab indent int[] stops = {16}; // change the indent SendMessage(this.textBox1.Handle, EM_SETTABSTOPS, 1, stops);