MarcosL

Hi everyone.
I have this problem:
I'm trying to make the cut, copy, and paste opcions for my edit menu.
i'm using a MDI from to hold the form where i want the text to be selected.
so, this is the code i use:


Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CutToolStripMenuItem.Click
'My.Computer.Clipboard.SetText(Me.ActiveMdiChild.ActiveControl.Text.tostring)
'Me.ActiveMdiChild.ActiveControl.Text = ""
End Sub

Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CopyToolStripMenuItem.Click
'my.Computer.Clipboard.SetText(Me.ActiveMdiChild.ActiveControl.Text.ToString)
End Sub

Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PasteToolStripMenuItem.Click
'My.Computer.Clipboard.GetText(Me.ActiveMdiChild.ActiveControl.Text.ToString)
End Sub

how can i make it copy only the selected text

Sry for my bad english



Re: Visual Basic Express Edition Coping a selected text to the clipboard?

Dave299

Me.ActiveMdiChild.ActiveControl returns an object of type Control, which does not have a SelectedText property. So to just copy the selected text you will have to cast the control to an object of a type which does have such a property. For instance this is how you could do it for a textbox

Dim TB As TextBox

If TypeOf Me.ActiveMdiChild.ActiveControl Is TextBox Then

TB = CType(Me.ActiveMdiChild.ActiveControl, TextBox)

Clipboard.SetText(TB.SelectedText)

TB.SelectedText = ""

End If





Re: Visual Basic Express Edition Coping a selected text to the clipboard?

MarcosL

Thx you.
i'm going to try it to see if it works.

thx you again =)





Re: Visual Basic Express Edition Coping a selected text to the clipboard?

MarcosL

well, cut and copy work just good. but i'm having problems making paste work. can you show me a sample code for paste





Re: Visual Basic Express Edition Coping a selected text to the clipboard?

Dave299

Well, its very similar

Dim TB As TextBox

If TypeOf Me.ActiveMdiChild.ActiveControl Is TextBox Then

TB = CType(Me.ActiveMdiChild.ActiveControl, TextBox)

TB.SelectedText = Clipboard.GetText

End If