Windows Forms: Insert image into RichTextBox in C#
By FoxLearn 3/16/2020 10:39:25 AM 8.71K
This post shows you How to Insert an image into a RichTextBox in C# Windows Forms Application.
Dragging RichTextBox, Button from Visual Studio toolbox to your form designer.
Adding a click event handler to the Open button allows you to select an image, then load image in RichTextBox control in C#.
private void btnOpen_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.png; *.bmp)|*.jpg; *.jpeg; *.gif; *.png; *.bmp"; if (ofd.ShowDialog() == DialogResult.OK) { Clipboard.SetImage(Image.FromFile(ofd.FileName)); richTextBox.Paste(); } } }
We will use OpenFileDialog class to open a dialog allows you to select an image, then copy the image to Clipboard.
Finally, you need to paste to RichTextBox control.
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024