Results 1 to 5 of 5

Thread: How To Use FileDialog To Add Image To RichTextBox Without Clipboard?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    How To Use FileDialog To Add Image To RichTextBox Without Clipboard?

    I have been searching around and can't seem to find what I am looking for. I would like to add an image to my richtextbox via a filedialog but have only found examples that copy the image to the clipboard first and then paste it to the richtextbox. I would rather just load the image directly to the richtextbox. How is this done? I am trying to do something like this:

    Code:
    richtextbox1.AppendText(OpenFileDialog1.FileName)
    This only loads the file string and does not actually load the image itself.
    I realize appendtext is probably not what I need for this I tried others like selectedrtf, rtf..
    I went through all of the commands for richtext and could not find anything that would work or seem to work.
    Last edited by DreamWarrior77; Jun 10th, 2019 at 11:30 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How To Use FileDialog To Add Image To RichTextBox Without Clipboard?

    Quote Originally Posted by DreamWarrior77 View Post
    How is this done?
    It isn't, which is why you couldn't find examples of it. The RichTextBox doesn't provide an interface for that so you'd have to do it by knowing how to manipulate the RTF data directly.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: How To Use FileDialog To Add Image To RichTextBox Without Clipboard?

    I see ok, but assuming I wanted to load the standard .jpg, .bmp. png, .gif formats what method would you recommend for achieving this?

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: How To Use FileDialog To Add Image To RichTextBox Without Clipboard?

    Usually you should use a bitmap. This can been converted into many object and many formats back and forth.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How To Use FileDialog To Add Image To RichTextBox Without Clipboard?

    If you use the Image.FromFile method, a Bitmap object (Bitmap inherits Image) will be created for all those file formats.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width