create a richtextbox on formload then drag and drop on Richtextbox

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
good morning to all =) ahmm here is the thing...sirs im currently having a problem dragging and dropping my label1.text to a richtextboxt which isnt created on design time...well im currently found a solution but i think it is only for a temporary solution
because i use a drag and drop i drag it to a textbox then it willl transfer the data to the richtextbox....through the use of the textbox... here is the code ive come through..
here is the variables

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Inherits System.Windows.Forms.Form

<span style="color:Blue; Private <span style="color:Blue; Const EM_CHARFROMPOS <span style="color:Blue; As Int32 = &HD7
<span style="color:Blue; Dim NewTab <span style="color:Blue; As <span style="color:Blue; New TabPage
<span style="color:Blue; Dim NewRTB <span style="color:Blue; As <span style="color:Blue; New RichTextBox
<span style="color:Blue; Const CtrlMask <span style="color:Blue; As <span style="color:Blue; Byte = 8
<span style="color:Blue; Dim RTB <span style="color:Blue; As <span style="color:Blue; New RichTextBox
<span style="color:Blue; Dim Tab <span style="color:Blue; As <span style="color:Blue; New TabPage
[/code]
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub Label2_MouseMove(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.MouseEventArgs) <span style="color:Blue; Handles Label2.MouseMove
<span style="color:Blue; If e.Button = Windows.Forms.MouseButtons.Left <span style="color:Blue; Then
<span style="color:Blue; Dim lbl <span style="color:Blue; As Label = <span style="color:Blue; DirectCast(sender, Label)
<span style="color:Green; Invoke the drag and drop operation.
lbl.DoDragDrop(lbl.Text, DragDropEffects.Move <span style="color:Blue; Or DragDropEffects.Copy)
<span style="color:Green; End If
<span style="color:Green; If e.Button = MouseButtons.Left Then
<span style="color:Green; lbl.DoDragDrop(lbl.Text, DragDropEffects.Copy)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]

and the label will be drag and drop to the textbox

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub TextBox1_DragDrop(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.DragEventArgs) <span style="color:Blue; Handles TextBox1.DragDrop
<span style="color:Green; TextBox1.SelectedText = e.Data.GetData(DataFormats.StringFormat)
NewRTB.Text = e.Data.GetData(DataFormats.Text).ToString
<span style="color:Green; If the Ctrl key was not pressed, remove the source text to effect a
<span style="color:Green; drag-and-drop move.
<span style="color:Blue; If (e.KeyState <span style="color:Blue; And CtrlMask) <> CtrlMask <span style="color:Blue; Then
<span style="color:Green; txtSource.Text = ""
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]


<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub TextBox1_DragEnter(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.DragEventArgs) <span style="color:Blue; Handles TextBox1.DragEnter
<span style="color:Green; Check to be sure that the drag content is the correct type for this
<span style="color:Green; control. If not, reject the drop.
<span style="color:Blue; If (e.Data.GetDataPresent(DataFormats.Text)) <span style="color:Blue; Then
<span style="color:Green; If the Ctrl key was pressed during the drag operation then perform
<span style="color:Green; a Copy. If not, perform a Move.
<span style="color:Blue; If (e.KeyState <span style="color:Blue; And CtrlMask) = CtrlMask <span style="color:Blue; Then
e.Effect = DragDropEffects.Copy
<span style="color:Blue; Else
e.Effect = DragDropEffects.Move
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Else
e.Effect = DragDropEffects.None
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]
<br/>
at formload i call this sub class

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub AddTab(<span style="color:Blue; Optional <span style="color:Blue; ByVal file <span style="color:Blue; As <span style="color:Blue; String = <span style="color:Blue; Nothing)

NewRTB.AllowDrop = <span style="color:Blue; True
NewTab.AllowDrop = <span style="color:Blue; True

<span style="color:Blue; Dim TabText <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "Untitled"
<span style="color:Blue; Dim RTBText <span style="color:Blue; As <span style="color:Blue; String = <span style="color:Blue; Nothing


<span style="color:Blue; If <span style="color:Blue; Not IsNothing(file) <span style="color:Blue; Then
<span style="color:Blue; If <span style="color:Blue; My.Computer.FileSystem.FileExists(file) <span style="color:Blue; Then
NewRTB.Tag = file

TabText = <span style="color:Blue; My.Computer.FileSystem.GetFileInfo(file).Name
<span style="color:Blue; Dim reader <span style="color:Blue; As <span style="color:Blue; New System.IO.StreamReader(file)
RTBText = reader.ReadToEnd

reader.Close()
<span style="color:Blue; Else
MsgBox(<span style="color:#A31515; "Sorry that file doesnt exist")
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If

NewTab.Text = TabText
NewTab.Tag = NewRTB

NewRTB.Parent = NewTab
NewRTB.Dock = DockStyle.Fill
NewRTB.Text = RTBText

TabControl1.TabPages.Add(NewTab)
TabControl1.SelectedTab = NewTab
Tab = NewTab
RTB = NewRTB

<span style="color:Green; RTB_DragDrop()
<span style="color:Green; new try code

<span style="color:Green; end
<span style="color:Blue; End <span style="color:Blue; Sub

[/code]

<br/>
can you help me out how can i drag and drop it on the created Richtextbox and now on the textbox/...

advance thank you again =)




View the full article
 
Back
Top