T
TheGanjaMan
Hi everyone,
I'm trying to code an event and seem to be stuck on something that might
seem pretty simple (I am a newbie...)
I have two textboxes on a form, I have a button on a form that is
supposed to copy selected text.
When I click the button I want the selected text to be copied into the
clipboard. I can do this by saying:
Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Copy.Click
If TextBox1.SelectionLength > 0 Then
My.Computer.Clipboard.SetText(TextBox2.SelectedText,
TextDataFormat.Text)
End If
If TextBox2.SelectionLength > 0 Then
My.Computer.Clipboard.SetText(TextBox1.SelectedText,
TextDataFormat.Text)
End If
End Sub
But I want the code to know which textbox has text selected in it without
me having to specify it. Suppose I had more textboxes for example it
would be tiresome to write the if statement for all the textboxes (or any
control for that matter)...
Is there a way to do this without specifying the control name all the
time, I would love to learn how...
Any help is welcome,
Thanks in advance to anyone willing to help.
I'm trying to code an event and seem to be stuck on something that might
seem pretty simple (I am a newbie...)
I have two textboxes on a form, I have a button on a form that is
supposed to copy selected text.
When I click the button I want the selected text to be copied into the
clipboard. I can do this by saying:
Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Copy.Click
If TextBox1.SelectionLength > 0 Then
My.Computer.Clipboard.SetText(TextBox2.SelectedText,
TextDataFormat.Text)
End If
If TextBox2.SelectionLength > 0 Then
My.Computer.Clipboard.SetText(TextBox1.SelectedText,
TextDataFormat.Text)
End If
End Sub
But I want the code to know which textbox has text selected in it without
me having to specify it. Suppose I had more textboxes for example it
would be tiresome to write the if statement for all the textboxes (or any
control for that matter)...
Is there a way to do this without specifying the control name all the
time, I would love to learn how...
Any help is welcome,
Thanks in advance to anyone willing to help.