New to Telerik UI for WinForms? Download free 30-day trial

InlineImage

The InlineImage class allows images to be displayed inside the document. The InlineImage can only be used in the context of a Paragraph class. As it is an inline element, it gets placed after the previous inline element untill the end of the line. If there is no space left, the element will be wrapped on the next line.

This topic will explain you how to use the InlineImage element.

Here is an example of how to add an InlineImage element in the code behind.

Section section = new Section();
Paragraph paragraph = new Paragraph();
Size size = new Size(236, 50);
ImageInline image = new ImageInline(Resources.Desert, size);
paragraph.Inlines.Add(image);
section.Children.Add(paragraph);
this.radRichTextBox1.Document.Sections.Add(section);

Dim section As New Section()
Dim paragraph As New Paragraph()
Dim stream As IO.Stream = GetImage()
Dim size As New Drawing.Size(236, 50)
Dim image As New ImageInline(stream, size, "png")
paragraph.Inlines.Add(image)
section.Children.Add(paragraph)
Me.RadRichTextBox1.Document.Sections.Add(section)

Add via UI

Here is an example of how to allow the user to select an image and add it to the document. For that purpose a RadButton and an OpenFileDialog are used. When the file path from the OpenFileDialog is obtained, create a new Bitmap with the file path to the image, and pass the image to the InsertImage() method of the RadRichTextBox. After calling the InsertImage() method, the image will appear in the document with its default width and height.

private void imageButton_Click(object sender, EventArgs e)
{
    OpenFileDialog openDialog = new OpenFileDialog();
    openDialog.Filter = "Images|*.png";
    openDialog.Multiselect = false;
    if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        Bitmap img = new Bitmap(openDialog.FileName);
        this.radRichTextBox1.InsertImage(img);
    }
}

Private Sub imageButton_Click(sender As System.Object, e As System.EventArgs) Handles imageButton.Click
    Dim openDialog As New OpenFileDialog()
    openDialog.Filter = "Images|*.png"
    openDialog.Multiselect = False
        If openDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Dim img As New Bitmap(openDialog.FileName)
        Me.RadRichTextBox1.InsertImage(img)
    End If
End Sub

In this article