Cut, Copy, Paste

Posted by vancejohnson2 on 28-Jul-2008 13:16

Has anyone done any code for the Cut, Copy, and Paste events on the menuStrip? If so, can you please share it with the group?

All Replies

Posted by jmls on 28-Jul-2008 15:48

Which menustrip ? Infragistics or MS ?

Posted by jmls on 28-Jul-2008 15:58

I presume it's the MS menustrip with the "standard" options added (File, Copy etc)

What are you wanting to do ? Copy & paste text ?

Posted by vancejohnson2 on 28-Jul-2008 16:08

It's the menu strip that's created when you create a new ABL MIDI form. I just want to be able to select text in any ultraTextEditor control, press ctrl-C, and have the text available on the clipboard. The designer stubs in the following code.

METHOD PRIVATE VOID CopyToolStripMenuItem_Click(sender AS System.Object, e AS System.EventArgs):

/* TODO: Use System.Windows.Forms.Clipboard to insert the selected text or images into the clipboard */

END.

Posted by jmls on 28-Jul-2008 16:34

try

CAST(THIS-OBJECT:ActiveControl,System.Windows.Forms.TextBox):Copy().

to copy

and this

THIS-OBJECT:ActiveControl:Text = System.Windows.Forms.Clipboard:GetText().

to paste

Posted by jmls on 28-Jul-2008 16:37

oh, dammit, I just saw that you are using the ultraTextEditor. Change the cast from

System.Windows.Forms.TextBox

to

Infragistics.Win.UltraWinEditors.UltraTextEditor

and it should then work for you

Posted by vancejohnson2 on 28-Jul-2008 16:38

Works great. Thanks!

Posted by jmls on 28-Jul-2008 16:39

yay! my first help on .net !

Posted by vancejohnson2 on 28-Jul-2008 16:41

The System.Windows.Forms.TextBox version works fine with ultraTextEditors too.

Posted by jmls on 28-Jul-2008 16:41

oh, ok

Posted by jmls on 28-Jul-2008 16:43

heh my ultra cast didn't work. I'll find a fix for that as well.

Posted by vancejohnson2 on 28-Jul-2008 16:48

Is there an easy way to only execute those lines in text editors? It blows up if I do control-C in an ultraDateTimeEditor. It would be nice to make it work with that control too, but ignore things like buttons.

Posted by jmls on 28-Jul-2008 16:53

As as basic test:

If Type-Of(THIS-OBJECT:ActiveControl,System.Windows.Forms.TextBox) THEN

CAST(THIS-OBJECT:ActiveControl,System.Windows.Forms.TextBox):Copy().

and

If Type-Of(THIS-OBJECT:ActiveControl,System.Windows.Forms.TextBox) THEN

THIS-OBJECT:ActiveControl:Text = System.Windows.Forms.Clipboard:GetText().

Posted by jmls on 28-Jul-2008 16:55

You should also look at the documention of System.Windows.Forms.Clipboard for more info - you can copy and paste images, spreadsheets etc etc

Posted by jmls on 28-Jul-2008 16:58

maybe this works because maybe the ultraedittext box has subclassed / inherited / whatever the standard ms textbox ...

Posted by vancejohnson2 on 28-Jul-2008 17:06

Thanks again for your help. The only problem is paste() overlays the entire contents of the editor, instead of just pasting it in at the position of the cursor. I'll look at the doc to see if I can find a solution.

Posted by jmls on 28-Jul-2008 17:09

in the paste trigger, use

CAST(THIS-OBJECT:ActiveControl,System.Windows.Forms.TextBox):Paste()

Posted by vancejohnson2 on 28-Jul-2008 17:13

Bingo. Thanks!

Posted by jmls on 28-Jul-2008 17:15

heh. Right, that's it. I'm off to catch some zzzz's. I'll Be back tomorrow!

This thread is closed