我需要在WinForms应用程序的RichTextBox控件中显示光标,即使它不在焦点上也是如此。我怎样才能做到这一点?我找到了WPF(How to keep WPF TextBox selection when not focused?)的唯一方法

最佳答案

您可以使用WinAPI ..

 [DllImport("user32.dll", EntryPoint = "ShowCaret")]
 public static extern long ShowCaret(IntPtr hwnd);
 [DllImport("user32.dll", EntryPoint = "HideCaret")]
 public static extern long HideCaret(IntPtr hwnd);


并在需要时致电ShowCaret

10-08 12:53