Change the shape of the RichTextBox cursor (caret)

Source: Internet
Author: User
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 (richtextbox?gotfocus );
}

Private void richtextboxinclugotfocus (Object sender, eventargs E)
{
This. begininvoke (New methodinvoker (changecaret ));
}

Private void richtextbox#selectionchanged (Object sender, eventargs E)
{
This. changecaret ();
}

Private void richtextbox#mousedown (Object sender, mouseeventargs E)
{
This. changecaret ();
}

Private void changecaret ()
{
Createcaret (this. richtextbox1.handle, intptr. Zero, 10, 15 );
Showcaret (this. richtextbox1.handle );
}

Private void richtextbox1_keyup (Object sender, keyeventargs E)
{
This. changecaret ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.