Custom Caret for WinForms TextBox

前端 未结 4 585
暗喜
暗喜 2020-11-30 09:43

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

4条回答
  •  星月不相逢
    2020-11-30 10:05

    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);
        }
    }
    

提交回复
热议问题