Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I write a Windows Form Application in VB.Net. I use a RichTextBox in my project. (It's name is activeRichTextBox). I add multi-selected images from FileDialog. When I click on add button, all multi-selected images are added in RTB without spaces. But, I'd like to add images with spaces (like pressed "TAB" button"). I use SendKeys.Send("{TAB}") command after paste image. But it doesn't work. How can I succeed to make this work?

VB
Public Sub InsertPicture()
        Try
            Dim GetPicture As New OpenFileDialog
            GetPicture.Multiselect = True
            GetPicture.Filter = "PNGs (*.png), Bitmaps (*.bmp), GIFs (*.gif), JPEGs (*.jpg)|*.bmp;*.gif;*.jpg;*.png|PNGs (*.png)|*.png|Bitmaps (*.bmp)|*.bmp|GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg"
            GetPicture.FilterIndex = 1
            GetPicture.InitialDirectory = "C:\"
            If GetPicture.ShowDialog = Windows.Forms.DialogResult.OK Then
                For a As Integer = 0 To GetPicture.FileNames.Count - 1
                    Dim SelectedPicture As String = GetPicture.FileNames(a)
                    Dim cboard As Object = Clipboard.GetData(System.Windows.Forms.DataFormats.Text)
                    Picture = New Bitmap(SelectedPicture)
                    new_Bitmap = New Bitmap(Picture, 200, 200)
                    new_Bitmap.Tag = SelectedPicture
                    Clipboard.SetImage(new_Bitmap)
                    Dim PictureFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)
                    If activeRichTextBox.CanPaste(PictureFormat) Then
                        activeRichTextBox.Paste(PictureFormat)
                        SendKeys.Send("{TAB}")
                    End If
                    Clipboard.Clear()
                    Clipboard.SetText(cboard)
                Next
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
Posted

1 solution

try pasting the tab in the way you do the picture.
 
Share this answer
 
Comments
bellatriks 12-Oct-15 2:53am    
Hi, thanks your answer but I'm sorry because I didn't understand. How can I paste the tab?
CoderzF1 12-Oct-15 18:35pm    
give the following a try.
replace the line sendkeys.send("{tab}") with

clipboard.settext (vbTab)
richtextbox.paste()
bellatriks 19-Oct-15 3:13am    
Thanks your answer. It is work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900