Hi there.....
I have the following code for dragging and dropping a .rtf file onto my rich text box from a web browser control (being used to navigate around files on my computer), opening the contents into the rtb on my form.
However, I'd like the name of the file that's just been opened to be "TextBox1.Text", so that my "Save" button will then be able to save any changes i make.
Any suggestions?
End Sub
I have the following code for dragging and dropping a .rtf file onto my rich text box from a web browser control (being used to navigate around files on my computer), opening the contents into the rtb on my form.
However, I'd like the name of the file that's just been opened to be "TextBox1.Text", so that my "Save" button will then be able to save any changes i make.
Any suggestions?
Code:
Private Sub tbUpperBody_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles tbUpperBody.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then 'get Data Present
Dim FileName As String() = CType(e.Data.GetData(DataFormats.FileDrop), String()) 'Obtain FileName
For Each FileContents As String In FileName 'Loop through each file
If File.Exists(FileContents) Then 'If it exists
Dim tr As TextReader = New StreamReader(FileContents) 'TextReader object to read contents
tbUpperBody.Rtf = tr.ReadToEnd() 'read contents of file
End If
Next FileContents
End If
End Sub
Private Sub tbUpperBody_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles tbUpperBody.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy 'Just copy
Else
e.Effect = DragDropEffects.None
End If