Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable/disable Cut/Copy/Paste menu and toolbar items in a generic way?

Tags:

winforms

I have a windows forms application with controls like textbox, combobox, datagridview etc. These controls allow a user to use the clipboad, i.e. cut/copy and paste text. It is also possible to delete text (which is not related to the clipboard).

My application has a menubar with an Edit item containing Cut/Copy/Paste/Delete items, and a toolbar with these items as well. How can I enable/disable these items properly depending in the state of the control having the focus?

I am looking for a generic way, i.e. I look for an implementation I do once, and can reuse for the future independent of the controls my application will use.

like image 789
nruessmann Avatar asked Sep 18 '08 12:09

nruessmann


People also ask

How do I enable copy and paste in mainframe?

To enable it, do the following: Click Edit > Preferences > Edit > Cut/Copy.

How do you stop copy and paste?

You can allow text selection, but prevent copy and cut functions using the oncopy, oncut and onpaste event attributes. By adding these attributes into a textbox's <input> tag, you can disable cut, copy and paste features. The user is left with the option to enter the field manually with these attributes set.

How do I copy and paste without the toolbar?

Press Ctrl+C on Windows and Linux or Command+C on Mac. Paste text: Position the cursor where you want to paste the text. Press Ctrl+V on Windows and Linux or Command+V on Mac.

How do you copy and paste on IBM?

Right-click the selection and select Copy. Hold down Shift and select the target cells, then click CTRL+V or CMD+V to paste.


1 Answers

There is no generic interface or set of methods for getting cut/copy/paste information from a windows forms control.

I suggest your best approach would be to create a wrapper class for each type of control. Then when you want to update the menu state you get the current control with focus and create the appropriate wrapper for it. Then you ask that wrapper for the state information you need. That way you only need to create a wrapper implementation for each type of control you use. Bit of a pain to start with but other time you only need to add the new controls you come across.

Clipboard information is much easier as you can ask the Clipboard singleton if it has data inside and what type it is. Then again you still need to ask the target control if it can accept that type of information so there is still extra work needs doing.

like image 138
Phil Wright Avatar answered Oct 01 '22 03:10

Phil Wright