自定义符的文本框的WinForms [英] Custom Caret for WinForms TextBox
本文介绍了自定义符的文本框的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个定制的超级像一个WinForms NET 2.0应用程序。我有一个面板中,你可以与硬件设备进行交互的一个多行TextBox。
I'm developing a custom HyperTerminal like application in a WinForms .Net 2.0 application. I have a multiline TextBox in a Panel in which you can interact with a hardware device.
我的客户希望有一个自定义插入符号,一个填充矩形的一个字符空间,而不是垂直线是默认的大小。
My customer wants to have a custom Caret, a filled rectangle the size of one character space instead of the vertical line that is by default.
我知道.NET不提供一个选项,默认情况下,要做到这一点,但一定要有某些Windows函数来做到这一点。
I know .Net does not provide an option to do this by default, but there must some Windows function to do it.
有没有人这样做过?
谢谢
罗吉尔
推荐答案
上有一个文本框假设形式:
Assume a form with a textbox on it:
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
[DllImport("user32.dll")]
static extern bool ShowCaret(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
CreateCaret(textBox1.Handle, IntPtr.Zero, 10, textBox1.Height);
ShowCaret(textBox1.Handle);
}
}
这篇关于自定义符的文本框的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文