Ticket T217259
Visible to All Users

InsertPicture under Caret

created 10 years ago

Hi

When i try to insert a floating picture with the function InsertPicture, the picture is always insert in the left corner, even if i specifie the caret position.

How could i insert a floating image after the caret position ?

All the Best

Jean LORDET

C#
richEditControl1.Document.InsertPicture(richEditControl1.Document.CaretPosition, DocumentImageSource.FromFile(@"image.jpg"));

Answers approved by DevExpress Support

created 10 years ago

Hello Jean,
The InsertPicture method executing results in inserting an image as a floating object. However, according to your scenario description you need to insert an inline  image. In this case, you need to use the ?InsertImage? method:

C#
richEditControl1.Document.InsertImage(richEditControl1.Document.CaretPosition, DevExpress.XtraRichEdit.API.Native.DocumentImageSource.FromStream(imageStream));

Please take special note that in version 14.2.5, this method is marked as obsolete, and you need to insert inline  images using the RichEditControl.Document.Images.Insert? method:

C#
richEditControl1.Document.Images.Insert(richEditControl1.Document.CaretPosition, DevExpress.XtraRichEdit.API.Native.DocumentImageSource.FromStream(imageStream));

I also attached a sample project to demonstrate this approach in action.
Is this what you are looking for?

    Show previous comments (3)
    DevExpress Support Team 10 years ago

      You are welcome, Jean!
      I am happy to hear that my assistance was helpful to you.
      Should you have additional questions regarding our products or need my further assistance, do not hesitate to contact me.

        I'm trying this same thing using the WinForms control and version 15.1, but my image always aligns along the left margin. Anything I need to change with the code to make it work on v15.1 WinForms?

        DevExpress Support Team 9 years ago

          Hello Miles,
          To process your recent post more efficiently, I created a separate ticket on your behalf: T307224: How to insert a picture into a caret position in WinForms RichEditControl. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.