none
VB2010 - how add embede controls to RichTextBox?

All replies

  • Hi Cambalinho,

    Please refer to the code below.

    Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.RichTextBox1.Controls.Add(New Button With {.Text = "New"})
    
            Me.RichTextBox1.Controls.Add(New Label With {.Text = "New", .Location = New Point(50, 100), .BackColor = Color.Bisque})
    
            Dim pb As New PictureBox With {.Image = New Bitmap("c:\rates.bmp")}
    
            pb.SizeMode = PictureBoxSizeMode.AutoSize
    
            AddHandler pb.MouseClick, AddressOf Clicked
    
            Me.RichTextBox1.Controls.Add(pb)
        End Sub
        Private Sub Clicked(ByVal sender As Object, ByVal e As EventArgs)
    
            MessageBox.Show("clicked")
    
        End Sub

    Hope It is helpful to you.

    Best regards,

    Cherry bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 21, 2017 3:07 AM
    Moderator
  • Hi Cambalinho,

    Please refer to the code below.

    Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.RichTextBox1.Controls.Add(New Button With {.Text = "New"})
    
            Me.RichTextBox1.Controls.Add(New Label With {.Text = "New", .Location = New Point(50, 100), .BackColor = Color.Bisque})
    
            Dim pb As New PictureBox With {.Image = New Bitmap("c:\rates.bmp")}
    
            pb.SizeMode = PictureBoxSizeMode.AutoSize
    
            AddHandler pb.MouseClick, AddressOf Clicked
    
            Me.RichTextBox1.Controls.Add(pb)
        End Sub
        Private Sub Clicked(ByVal sender As Object, ByVal e As EventArgs)
    
            MessageBox.Show("clicked")
    
        End Sub

    Hope It is helpful to you.

    Best regards,

    Cherry bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    theres 1 big problem with these: the controls aren't embed with text. we can write on back of  the controls.
    Friday, April 21, 2017 10:44 AM
  • theres 1 big problem with these: the controls aren't embed with text. we can write on back of  the controls.
    Do you mean that you want the controls to be part of the RTF text?  Use the Paste() method for that.
    Friday, April 21, 2017 10:23 PM
  • how?

    i did:

    Public Sub InsertImage2(ByVal objImage As Object)
            'Dim myBitmap As Image = Image.FromFile(strImage)
            Clipboard.SetDataObject(objImage)
    
            'Dim myFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.)
            Me.Paste()'me it's the richtextbox
        End Sub

    but nothing happens.

    how can i copy and paste controls?


    • Edited by Cambalinho Friday, April 21, 2017 10:50 PM
    Friday, April 21, 2017 10:50 PM
  • how can i copy and paste controls?

    A control, or an image of a control?

    I don't know what might happen if you pasted a control, but I doubt it would be useful.   You can paste an image of a control using the code you already have. This example pastes an image of ListBox1 into RichTextBox1.

            Dim X As Integer = ListBox1.Width
            Dim Y As Integer = ListBox1.Height
            Dim Xoffs As Integer = Me.PointToScreen(ListBox1.Location).X
            Dim Yoffs As Integer = Me.PointToScreen(ListBox1.Location).Y
            Dim objimage As New Bitmap(X, Y)
            Dim gfxPaneShot As Graphics = Graphics.FromImage(objimage)
            gfxPaneShot.CopyFromScreen(Xoffs, Yoffs, 0, 0, objimage.Size, CopyPixelOperation.SourceCopy)
            Clipboard.SetDataObject(objimage)
            RichTextBox1.paste()

    Friday, April 21, 2017 11:32 PM
  • how can i copy and paste controls?

    A control, or an image of a control?

    I don't know what might happen if you pasted a control, but I doubt it would be useful.   You can paste an image of a control using the code you already have. This example pastes an image of ListBox1 into RichTextBox1.

            Dim X As Integer = ListBox1.Width
            Dim Y As Integer = ListBox1.Height
            Dim Xoffs As Integer = Me.PointToScreen(ListBox1.Location).X
            Dim Yoffs As Integer = Me.PointToScreen(ListBox1.Location).Y
            Dim objimage As New Bitmap(X, Y)
            Dim gfxPaneShot As Graphics = Graphics.FromImage(objimage)
            gfxPaneShot.CopyFromScreen(Xoffs, Yoffs, 0, 0, objimage.Size, CopyPixelOperation.SourceCopy)
            Clipboard.SetDataObject(objimage)
            RichTextBox1.paste()


    you are copy what is on screen. so i lose the big objective. i need add emebeded controls on richtextbox(like a picturebox for not lose the gif animation)

    • Edited by Cambalinho Saturday, April 22, 2017 9:58 AM
    Saturday, April 22, 2017 9:55 AM
  • you are copy what is on screen. so i lose the big objective. i need add emebeded controls on richtextbox(like a picturebox for not lose the gif animation)

    If that was the big objective it should have been mentioned in the first post.

    To get an animated GIF to be animated in a rich text box, use the code provided here to insert the control:
    https://www.codeproject.com/Articles/134358/TRichTextBox-A-universal-RichTextBox-which-can-dis

    Saturday, April 22, 2017 10:29 AM
  • you are copy what is on screen. so i lose the big objective. i need add emebeded controls on richtextbox(like a picturebox for not lose the gif animation)

    If that was the big objective it should have been mentioned in the first post.

    To get an animated GIF to be animated in a rich text box, use the code provided here to insert the control:
    https://www.codeproject.com/Articles/134358/TRichTextBox-A-universal-RichTextBox-which-can-dis

    i'm sorry, but did you test that project?

    the Richtextbox is ReadOnly, so i change it to false.

    i copy the 3rd line(where is the image) for the 4th line. like you see, i write text on back of the image(picturebox).

    i think that the only way for resolve these(the complex and hard way) is protect the text on control dimensions. i did that, but it must be dependent on text change.

    i accept sugestions

    Saturday, April 22, 2017 10:43 AM