Results 1 to 3 of 3

Thread: copy and paste to clipboard method

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    6

    Unhappy copy and paste to clipboard method

    Hi fellas...

    So I'm doing this copy and paste to clipboard coding. It's running fine though. Below are the codes.

    VB Code:
    1. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCopy.Click
    2.         Clipboard.SetDataObject(txtSource.Text, False)
    3.     End Sub
    4.  
    5.  Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPaste.Click
    6.         txtDest.Text = Clipboard.GetDataObject.GetData(DataFormats.Text, True)
    7.     End Sub

    There is no problem for pasting from clipboard. The copy code is running fine but as you can see we can only have text from text box named txtSource. How about if we like to copy from any highlighted word. Maybe we should change the txtSource into some other commands perhaps or maybe to call another function.
    Hope you all can give me some tips. Thanx in advance...


  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    This code will copy any text which has been selected, or all of the textbox's text if no words have been selected...
    VB Code:
    1. If (txtSource.SelectionLength > 0) then
    2.     clipboard.SetDataObject (mid(txtSource.Text, _
    3.     txtSource.SelectionStart, txtSource.SelectionLength).ToString)
    4. Else
    5.     clipboard.SetDataObject (txtSource.Text)
    6. End if

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    6
    Well that is not exactly what I had in mind. What I meant by any higlighted words are like highlighting at the web page, the ms word, notepad etc. So basically what you mentioned is all about the same text box. And what I meant is anything that is highlighted. But thanx anyway....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width