using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
    
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();
            richTextBox1.GotFocus 
+= new EventHandler(richTextBox1_GotFocus);
        }

        
private void richTextBox1_GotFocus(object sender, EventArgs e)
        {
            
this.BeginInvoke(new MethodInvoker(ChangeCaret));
        }

        
private void richTextBox1_SelectionChanged(object sender, EventArgs e)
        {
            
this.ChangeCaret();
        }

        
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
        {
            
this.ChangeCaret();
        }

        
private void ChangeCaret()
        {
            CreateCaret(
this.richTextBox1.Handle, IntPtr.Zero, 1015);
            ShowCaret(
this.richTextBox1.Handle);
        }

        
private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
        {
            
this.ChangeCaret();
        }
    }
}

相关文章:

  • 2021-10-29
  • 2021-11-14
  • 2021-08-03
  • 2021-09-11
  • 2021-11-04
  • 2021-07-06
  • 2021-07-11
猜你喜欢
  • 2021-12-22
  • 2021-10-26
  • 2021-09-16
  • 2021-10-27
  • 2021-11-14
  • 2021-09-06
  • 2021-09-06
  • 2021-11-14
相关资源
相似解决方案