drag and drop problem... vb .net
-
Please can someone tell me how to drag a file from my explorer window on my form and load the file into a rich text box that i have created at runtime? thank you, in advance
on formload textbox1.dragdrop=true
Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop If (System.IO.File.Exists(CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString()) = True) Then If (System.IO.Path.GetExtension(CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString()) = ".txt") Then TextBox1.Text = System.IO.File.ReadAllText(CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString()) Else MessageBox.Show("select the .txt extention file") End If End If End Sub Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then e.Effect = DragDropEffects.Copy End If End Sub
Hope this may help You.:) -
on formload textbox1.dragdrop=true
Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop If (System.IO.File.Exists(CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString()) = True) Then If (System.IO.Path.GetExtension(CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString()) = ".txt") Then TextBox1.Text = System.IO.File.ReadAllText(CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString()) Else MessageBox.Show("select the .txt extention file") End If End If End Sub Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then e.Effect = DragDropEffects.Copy End If End Sub
Hope this may help You.:) -
Thanks for the code... technically that should work, but I create my rich text box at runtime, so i cant call its events, or atleast... i am unsure of how to! :confused: please help? thanx guys!
DaxBooysen wrote:
i am unsure of how to! please help?
replace textbox with Richedittextbox Actually i tried it with textbox.It is very simple. replace textbox with richedittextbox
-
DaxBooysen wrote:
i am unsure of how to! please help?
replace textbox with Richedittextbox Actually i tried it with textbox.It is very simple. replace textbox with richedittextbox
-
I have no problem with that, its the fact that i create it at RUNTIME... i dont place it on my form at design time, so when i try make an event for a text box that has not been created yet i cant! know what i mean? thanx again!:confused:
ok What code u r writing?
-
ok What code u r writing?
i create a rtf box in many places and set it as a child control of a tab control... but i call it up like this when i want to change its values...
Dim rtf As New RichTextBox() rtf = TABS.TabPages(TABS.SelectedIndex).Controls.Item(0)
and so you see... since its created at runtime... how do i call its events? thanx, dax :) -
i create a rtf box in many places and set it as a child control of a tab control... but i call it up like this when i want to change its values...
Dim rtf As New RichTextBox() rtf = TABS.TabPages(TABS.SelectedIndex).Controls.Item(0)
and so you see... since its created at runtime... how do i call its events? thanx, dax :)then write the code on each control which is provided to u.
-
i create a rtf box in many places and set it as a child control of a tab control... but i call it up like this when i want to change its values...
Dim rtf As New RichTextBox() rtf = TABS.TabPages(TABS.SelectedIndex).Controls.Item(0)
and so you see... since its created at runtime... how do i call its events? thanx, dax :)DaxBooysen wrote:
Dim rtf As New RichTextBox() rtf = TABS.TabPages(TABS.SelectedIndex).Controls.Item(0)
Doesn't this create a control, then discard it for one that's already within the tab page ? Either way, you can attach events to a control in code, at least you can in C#.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Thanks for the code... technically that should work, but I create my rich text box at runtime, so i cant call its events, or atleast... i am unsure of how to! :confused: please help? thanx guys!
If you create a control at runtime, you have to wire up the events yourself at runtime, just like the designer generated code does when you drop a control on the form. Lookup AddHandler and RemoveHandler on MSDN and it'll show you how to do this...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
If you create a control at runtime, you have to wire up the events yourself at runtime, just like the designer generated code does when you drop a control on the form. Lookup AddHandler and RemoveHandler on MSDN and it'll show you how to do this...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007