Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cut, Copy, Paste Event needed.

Cut, Copy, Paste Event needed.

Scheduled Pinned Locked Moved C#
help
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nicholas Cardi
    wrote on last edited by
    #1

    I am trying to implement cut copy and paste in my application. I have the cut,copy and paste buttons on a toolbar and they are always visible. I have tried hooking the Controls Enter event but this solves only half the problem. I also need to be able to tell if text is being highlighted. This is not on a menu so I cannot just hook the menu_click event Thanks in Advance Forever Developing

    J H P 3 Replies Last reply
    0
    • N Nicholas Cardi

      I am trying to implement cut copy and paste in my application. I have the cut,copy and paste buttons on a toolbar and they are always visible. I have tried hooking the Controls Enter event but this solves only half the problem. I also need to be able to tell if text is being highlighted. This is not on a menu so I cannot just hook the menu_click event Thanks in Advance Forever Developing

      J Offline
      J Offline
      je_gonzalez
      wrote on last edited by
      #2

      I ran into this and solved it in a funny way... Instead of using the TextBox control, I subclassed the RichTextBox to mimic an "Enhanced" TextBox. In the subclass set the Multiline property to false, and the height to 20. This essentialy makes the RichTextBox look like TextBox. Now you can hook into the SelectionChanged event and check the Can properties to enable/disable your buttons. Call the SelectionChanged handler from the Enter event for the object to handle the initial setup.

      1 Reply Last reply
      0
      • N Nicholas Cardi

        I am trying to implement cut copy and paste in my application. I have the cut,copy and paste buttons on a toolbar and they are always visible. I have tried hooking the Controls Enter event but this solves only half the problem. I also need to be able to tell if text is being highlighted. This is not on a menu so I cannot just hook the menu_click event Thanks in Advance Forever Developing

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        A good way is to take advantage that WM_COMMAND messages are passed to a control's parent (keep in mind that all controls in System.Windows.Forms are just wrapper classes for Windows Common Controls). If you override WndProc in your main form, all child controls - as well as their children, and so forth - will send you a WM_COMMAND message that you can mask for the EN_SETFOCUS or EN_SELCHANGE notification message. You then use the Message.HWnd property to get the Window handle (HWND) and use Control.FromChildHandle to get the control. You can then cast it to a TextBoxBase (base class for both TextBox and RichTextBox) and call the Cut, Copy, or Paste methods on it.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        1 Reply Last reply
        0
        • N Nicholas Cardi

          I am trying to implement cut copy and paste in my application. I have the cut,copy and paste buttons on a toolbar and they are always visible. I have tried hooking the Controls Enter event but this solves only half the problem. I also need to be able to tell if text is being highlighted. This is not on a menu so I cannot just hook the menu_click event Thanks in Advance Forever Developing

          P Offline
          P Offline
          panache1023
          wrote on last edited by
          #4

          I got a great idea. It is a little bit cheesy, but it appears that Microshnizzle does it this way alot, so if they can do it, so can we! Make ONE function for each of the following handlers and subscribe all of your text boxes to it. 1. Mouse UP 2. Key press (interested in the left and right arrows) When either of these events is fired, check the Selection for the Textbox (Textbox.SelectionLength). If the selection Length is NOT zero, then Enable your cut and copy buttons, if the length is 0, nothing to copy, so Disable the cut and copy buttons!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups