Results 1 to 6 of 6

Thread: Cut, Copy, Paste [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311

    Resolved Cut, Copy, Paste [RESOLVED]

    Hello....

    If no text is selected in my textbox, I don't want the copy or cut functions to be available on my toolbar/menu. Likewise if the clipboard is empty I don't want to Paste to be available.

    I'm thinking that on the keypress/mousemove/any activity events of my textbox I could put in the appropriate code to enable and disable the relevant options. But this seems a bit messy to me. Is this the correct way to go about doing this or does anyone know of a better way?

    Thanks
    Last edited by Help321; Sep 30th, 2004 at 11:29 AM.

  2. #2
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Hi, take a look at the code in the attachment. Note that the Clipboard.GetText method only works for plain text (e.g. normal text boxes). If you want to check if any Rich Text has been placed on the clipboard, for example, you need to use the RegisterClipboardFormat API. That's a bit tricky, but so far it looks like you don't need that.
    Attached Files Attached Files
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311
    That's perfect for half of my problem, thanks.

    Have you got any ideas on how to do this for cut, copy and paste icons on a toolbar?

  4. #4
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Hmm, that's more difficult since there is no specific event generated when clipboard actions take place. Take a look at the attached example. I used the Click and KeyUp events and it works well, as far as I've tested.

    One problem is this; when the CheckButtons function has found text on the clipboard and enables the Paste button, the user switches to another application and erases the text from the clipboard, the button will still be active until CheckButtons is called once again. Perhaps you should also call the CheckButtons function when the form is activated. Play around with it; I don't know how reliable this code is. There may be better solutions.
    Attached Files Attached Files
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311
    Cheers again. This is the route I was going down. As you say, there may be better solutions, but for now I'll go down this path. Thanks again for your help, appreciate it.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311
    I have put the code to disable/enable the relevant menu options and toolbar options in the Click Event of the Edit menu.

    Then called these on the key_up and mouse_up events of my textbox.

    Enjoy

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