Cut, Copy, Paste Event needed.
-
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
-
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
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.
-
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
A good way is to take advantage that
WM_COMMAND
messages are passed to a control's parent (keep in mind that all controls inSystem.Windows.Forms
are just wrapper classes for Windows Common Controls). If you overrideWndProc
in your main form, all child controls - as well as their children, and so forth - will send you aWM_COMMAND
message that you can mask for theEN_SETFOCUS
orEN_SELCHANGE
notification message. You then use theMessage.HWnd
property to get the Window handle (HWND
) and useControl.FromChildHandle
to get the control. You can then cast it to aTextBoxBase
(base class for bothTextBox
andRichTextBox
) and call theCut
,Copy
, orPaste
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-----
-
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
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!