DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Adding 2 images into rich text box using clib board method

  1. #1
    Join Date
    May 2005

    Adding 2 images into rich text box using clib board method

    Hello I am trying to inset insert 2 images in to rich text box, this is what I have tried:

    Using OLE:
    RichTextBox1.OLEObjects.Add , , strPicDestination
    But the problem with this method is that it places a thumbnail into the text box and opens the image up with MS paint
    Also I cant control the location of where the image is inserted

    Then someone recommended me to use windows API in user32.dll you have SendMessageA that allows you to paste the image into rich text box from a clip board
    You can find the exact syntax of how I am doing that here:

    Anyways my problem is:

    When I try to paste more then one image this way, the previous image gets replaced by the new images, so that I have only 1 images in a rich text box at all times.

    I am not sure what is the cause of this could anyone think of why this happens


    This is the syntax in a more confusing way if the link doesn’t work

    Option Explicit

    Private Const WM_PASTE = &H302
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Private Sub Form_Load()
    RichTextBox1.Text = "hi, hello, how are you doing ?"
    End Sub

    Private Sub Form_Resize()
    With Command1
    RichTextBox1.Move 0, 0, ScaleWidth, ScaleHeight - .Height
    .Move 0, ScaleHeight - .Height, ScaleWidth
    End With 'Command1
    End Sub

    Private Sub Command1_Click()
    Dim lngStart As Long
    Dim strFind As String
    Clipboard.SetData LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\BALLOON.BMP")
    strFind = "hello,"
    With RichTextBox1
    lngStart = Instr(.Text, strFind)
    .Text = Left$(.Text, lngStart - 1) & Mid$(.Text, lngStart + Len(strFind))
    .SelStart = lngStart - 1
    SendMessage .hwnd, WM_PASTE, 0, 0
    End With 'RichTextBox1
    End Sub

  2. #2
    Join Date
    Apr 2005
    South Africa
    Hope this helps, It worked for me, to insert an image into richtextbox with a commondialog!

    Private Sub cmdInsertPicture_Click()
    Dim sFile As String
        Image1.Picture = Nothing
        With CommonDialog1
            .DialogTitle = "Open Picture"
            .CancelError = False
            'ToDo: set the flags and attributes of the common dialog control
            .Filter = "Pictures (*.bmp)"
                If Len(.FileName) = 0 Then
                    Exit Sub
                End If
            sFile = .FileName
        End With
    'Populate the clipboard with image picture
        Image1.Picture = LoadPicture(sFile)
        Clipboard.SetData Image1.Picture
        SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0
        Image1.Picture = Nothing
    End Sub
    ** <<]db[>> **
    *** G.s.G Crew ***

  3. #3
    Join Date
    Jan 2007

    This works great for me.

    Private Sub btnRTFAddImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRTFAddImage.Click
    imgDialog.Filter = "JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|Gif Images (*.gif)|*.gif|Bitmaps (*.bmp)|*.bmp"
    imgDialog.FilterIndex = 1
    If imgDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
    Dim img As New System.Drawing.Bitmap(imgDialog.FileName)
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center