-
May 15th, 2012, 03:14 PM
#1
Thread Starter
Member
Form Drag And Drop From Computer Help!
I am in process of making a advanced note pad and have figured and most of the things i need out but i need help making a drag and drop system so i can take a .txt file from my computer and drag it on the program and drop it and have the program load the .txt file.
Please help!
P.S : it is a tabbed notepad
Code for open:
Code:
Dim OPF As New OpenFileDialog
Dim AllText As String = "", LineOfText As String = ""
OPF.Filter = "Text Document(*.txt*)|*.txt|All Files|*.*"
OPF.ShowDialog()
UseWaitCursor = True
Try
FileOpen(1, OPF.FileName, OpenMode.Input)
Do Until EOF(1)
LineOfText = LineInput(1)
AllText = AllText & LineOfText & vbCrLf
Loop
UseWaitCursor = True
CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text = AllText
UseWaitCursor = False
Catch
Finally
FileClose(1)
End Try
-
May 15th, 2012, 03:32 PM
#2
Re: Form Drag And Drop From Computer Help!
here's an example with a standard textbox:
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.AllowDrop = True
End Sub
Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim file As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()).First
TextBox1.Text = IO.File.ReadAllText(file)
End If
End Sub
Private Sub TextBox1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragOver
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2012, 04:01 PM
#3
Thread Starter
Member
Re: Form Drag And Drop From Computer Help!
I NEED it to be for richtextbox using tabcontrol. The above reply did not help me.
Please help!
-
May 15th, 2012, 04:05 PM
#4
Re: Form Drag And Drop From Computer Help!
the same principles apply for a rtb as for a textbox. whether the rtb is in a tabpage or not is irrelevant
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2012, 04:11 PM
#5
Thread Starter
Member
Re: Form Drag And Drop From Computer Help!
well,i am a beginner (kinda) (1 year) and i would love if you could show the actual code with the richtextbox in use. I would REALLLLLY appreciate it.
-
May 15th, 2012, 04:28 PM
#6
Re: Form Drag And Drop From Computer Help!
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2012, 04:30 PM
#7
Thread Starter
Member
Re: Form Drag And Drop From Computer Help!
Originally Posted by .paul.
is it plain text or rtf?
should be plain text.
-
May 15th, 2012, 04:35 PM
#8
Re: Form Drag And Drop From Computer Help!
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each tp As TabPage In TabControl1.TabPages
Dim rtb As RichTextBox = DirectCast(tp.Controls(0), RichTextBox)
rtb.AllowDrop = True
AddHandler rtb.DragEnter, AddressOf rtb_DragEnter
AddHandler rtb.DragDrop, AddressOf rtb_DragDrop
Next
End Sub
Private Sub rtb_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Dim rtb As RichTextBox = DirectCast(sender, RichTextBox)
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim file As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()).First
rtb.Text = IO.File.ReadAllText(file)
'for rtf, use this instead:
'rtb.LoadFile(file)
End If
End Sub
Private Sub rtb_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2012, 04:43 PM
#9
Thread Starter
Member
Re: Form Drag And Drop From Computer Help!
Originally Posted by .paul.
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each tp As TabPage In TabControl1.TabPages
Dim rtb As RichTextBox = DirectCast(tp.Controls(0), RichTextBox)
rtb.AllowDrop = True
AddHandler rtb.DragEnter, AddressOf rtb_DragEnter
AddHandler rtb.DragDrop, AddressOf rtb_DragDrop
Next
End Sub
Private Sub rtb_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Dim rtb As RichTextBox = DirectCast(sender, RichTextBox)
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim file As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()).First
rtb.Text = IO.File.ReadAllText(file)
'for rtf, use this instead:
'rtb.LoadFile(file)
End If
End Sub
Private Sub rtb_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
End Class
I am getting errors here:
Code:
Dim file As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()).First
and here:
Code:
Dim rtb As RichTextBox = DirectCast(tp.Controls(0), RichTextBox)
Please help!
-
May 15th, 2012, 04:53 PM
#10
Re: Form Drag And Drop From Computer Help!
which framework are you targetting?
what controls do you have on your tabpages? if the control at index 0 is not a rtb, you'll get an error
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2012, 04:57 PM
#11
Thread Starter
Member
Re: Form Drag And Drop From Computer Help!
Originally Posted by .paul.
which framework are you targetting?
what controls do you have on your tabpages? if the control at index 0 is not a rtb, you'll get an error
Targeting: 4.0
My control is: 0
Errors: Yes
-
May 15th, 2012, 05:08 PM
#12
Re: Form Drag And Drop From Computer Help!
do you have a rtb at index 0 on every tabpage?
for the other error, try this instead:
vb Code:
Dim file As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())(0)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2012, 05:09 PM
#13
Re: Form Drag And Drop From Computer Help!
also it'd be helpful to provide the error messages
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2012, 05:13 PM
#14
Thread Starter
Member
Re: Form Drag And Drop From Computer Help!
Originally Posted by .paul.
also it'd be helpful to provide the error messages
ok, i fixed every error now but when i have multiple tabs open and try to drag a .txt into any page besides page 1 it dosnt work.
-
May 15th, 2012, 05:16 PM
#15
Re: Form Drag And Drop From Computer Help!
it should drop only on the currently selected tab's rtb
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|