C realizes the method of inserting pictures in the specified cursor position by RichTextBox in winform

  • 2021-10-13 08:28:23
  • OfStack

In this paper, an example of C # to achieve winform RichTextBox in the specified cursor position insertion method. Share it for your reference, as follows:


// Get RichTextBox The index position of the mouse focus in the control  
int startPosition = this.richTextBox1.SelectionStart;
// Select a few characters from the focus of the mouse 
this.richTextBox1.SelectionLength = 2;
// Empty the clipboard to prevent it from having previous contents 
Clipboard.Clear();
// Set the picture object for the clipboard 
Bitmap bmp = new Bitmap(@"Images\editredo.png");
Clipboard.SetImage(bmp);
// Paste the picture into the focus of the mouse ( Due to the selection 2 Characters, so that 2 Characters will be overwritten by the picture )
richTextBox1.Paste();
Clipboard.Clear();

For more readers interested in C # related content, please check out the topics on this site: "C # Common Control Usage Tutorial", "C # Data Structure and Algorithm Tutorial", "C # Object-Oriented Programming Introduction Tutorial" and "C # Programming Thread Use Skills Summary"

I hope this article is helpful to everyone's C # programming.


Related articles: