Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard '{CTRL+V}' and Keyboard '{CTRL+C}' 1

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

This is probably staring me in the face, but I need your advice guys:

I have the following command in the right click event of a text box to allow the user to "Paste" in text:
Code:
Keyboard '{CTRL+V}'
I am aware that:
Code:
Keyboard '{CTRL+C}'
will allow the "Copying" of text.

What I am trying to achieve is for the user to click into a field (text box) on a form, be able to copy all the text contained in that text box using an automated process (such as Keyboard '{CTRL+C}')

It's quite easy to use the keyboard (CTRL&C) but that's not what we are after.

I can't use left click because that would mean every time someone clicked into the text box, it would be asking to "Copy", I cant use right click (already being used by Keyboard '{CTRL+V}' and finally, if you highlight all the text in the field (text box) and then click on it (Or double click on a word) it only highlights one word and not all of them.

I have though about using a Function key to achieve CTRL&C but if the mouse can be used, that would be more appropriate for this project.

Some guidance would be very much appreciated.

Thank you

Lee


 
why put CTRL+C on a key? Isn't it simple enough already?

Mouses today mostaly have three or even more buttons. While VFP does not support this, WinAPI will let you test for the middle mouse button, besides that you could support mouse gestures. Eg interpret a bow made by mouse movements roughly in the shape of a C for Copy.

Bye, Olaf.
 
Lee,

Why don't you have the right-click fire a simple context menu, from which the user can choose Cut, Copy, Paste, Select All, or whatever else you like? This is easy to do, and has the big advantage of being consistent with other Windows apps. The user will be able to use the mouse to pick from the menu, or hit the usual keyboard shortcuts if they prefer.

All you have to do is create a menu in the Menu Designer, choosing "Shortcut" rather than "Menu" when prompted. Use the Insert Bar button to insert the standard Edit menu items. That way, you won't have to create the menu bars manually, and all the shortcut keys will be automatically activated.

I know this doesn't directly answer your question, but it will achieve the same goal, and also give your app a nice professional touch.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 

Hi Mike

Thank you for the very constructive reply. I have created the menu as you have suggested (Select all / Copy / Paste / Cut) and would hold my hands up saying I've not created one like this before and didn't realise how simple it was!

My only slight problem now is how to add this to a particular text box and get it to show if I right click in the box itself.

I have checked the help file but as usual, it's not very helpful.

Any advice / guidance would be appreciated.

Thanks again for your reponse.

Lee
 
In the right-click method of the textbox, call the menu program:

DO MyMenu.MPR

Tamar
 

Hi Tamer

Having put the command as suggested in the right click event, when you run it says menu not found.

I am calling the menu menu1 to make it easy.

Any idea why the menu is not being found?

Lee
 
If you adress any file just by it's name, you first need to CD into it's directory or have it in all the paths of SET PATH. That's true for tables and also menu prgs.

Have you generated the menu prg? While you're in the menu designer, you have a menu "Menu", go there and choose "Genereate", now a menu1.mpr is generated, otherwise you just have an mnx file, that's not a prg.

Bye, Olaf
 
Lee,

First, make sure the menu program is in your search path.

Second, remember that when the menu designer generates a program, it gives it the extension MPR (rather than the usual PRG). So, in your right-click, you need:

DO Menu1.MPR

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 

Mike / Olaf

I think where I'm missing something is the fact that after I have created the menu, I end up with MENU1.MNT and MENU1.MNX

There is no MENU1.MPR so how do I "generate" that file?

Sorry if this easy for some, but it's new for me.

Thank you

 
Open the menu in the IDE using modify.

On the menu bar there will be an entry after 'program' entitled 'menu'.

On that, pick 'Generate' - that will make your file.

Martin

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 

All

Thank you for your assistance.

I have managed to generate the menu as described by Griff and Mike.

Kind regards to all who posted on this thread

Lee
 
Just out of curiosity, is the answer I gave about generating the MPR file ~three hours before you asked how to do this not visible to all? Is there a forums bug, perhaps?

Bye, Olaf.
 
Olaf

I can see it, but I didn't notice it earlier, or I would not have answered the question a second time.

B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 

Olaf

You mentioned:
Have you generated the menu prg? While you're in the menu designer
I enquired:
There is no MENU1.MPR so how do I "generate" that file?
I did see your post my friend, but I wasn't sure how to do it.

Hope that clears up your question.

Kind regards

Lee

 
If you had read on...

While you're in the menu designer, you have a menu "Menu", go there and choose "Genereate"

Well, doesn't matter, finally you found it.

Bye, Olaf.
 
Lee here is an easy way to do what you want; You can put the following code in a prg as well. We have it in a class;
Code:
Parameter oRef
Define Popup edtshort SHORTCUT Relative From Mrow(),Mcol()
Define Bar 1 Of edtshort Prompt "\<Font..."
Define Bar 2 Of edtshort Prompt "\-"
Define Bar _Med_cut Of edtshort Prompt "Cu\<t" ;
	KEY CTRL+X, "Ctrl+X" ;
	MESSAGE "Removes the selection and places it onto the Clipboard"
Define Bar _Med_copy Of edtshort Prompt "\<Copy" ;
	KEY CTRL+C, "Ctrl+C" ;
	MESSAGE "Copies the selection onto the Clipboard"
Define Bar _Med_paste Of edtshort Prompt "\<Paste" ;
	KEY CTRL+V, "Ctrl+V" ;
	MESSAGE "Pastes the contents of the Clipboard"
Define Bar _Med_clear Of edtshort Prompt "Cle\<ar" ;
	MESSAGE "Removes the selection and does not place it onto the Clipboard"
Define Bar 6 Of edtshort Prompt "\-"
Define Bar 7 Of edtshort Prompt Iif(Vartype(oRef.Value) = "C","\<Format","\Format");
	MESSAGE "Formats the selection"
*If !NoWord
Define Bar 8 Of edtshort Prompt "\-"
Define Bar 9 Of edtshort Prompt Iif(Vartype(oRef.Value) = "C" ;
	AND !Empty(oRef.Value) ;
	AND !NoWord,"\<Spelling","\Spelling");
	MESSAGE "checks the spelling"
*Endif
Define Bar 10 Of edtshort Prompt Iif(Vartype(oRef.Value) = "D","\<Calendar","\Calendar");
	MESSAGE "Opens a Calendar, Replaces the selections value with the date selected"
*If !NoWord
On Selection Bar 9 Of edtshort itsapp.checkspelling(oRef)
*Endif
On Selection Bar 1 Of edtshort itsapp.changefont(oRef)
On Selection Bar 7 Of edtshort itsapp.Beautify(oRef)
On Selection Bar 10 Of edtshort itsapp.dispcalander(oRef)

Activate Popup edtshort
Delete bar 7 - 10, unless you want these and I will post the code for you.

Now in the textbox class's right-click;
Code:
	itsapp.editshort(This)
	this.SetFocus()

*itsapp is a class and editshort is a method in itsapp, but if you have the menu in a prg just change this to 
do <<prg name>> with THIS

 

imaginecorp

Thank you for the excellent post which I take on board. This is a very extensive menu (above and beyond of the requirement) but worthy of a star.

Kind regards


Lee
 
Thank You... I have always disliked the menu generator or .mpr, rather have used the code generated to put in a class method or prg... IMO gives one more control when changes are required...
 
I agree with that, Imaginecorp. On the other hand, it's quite useful to use the generator to produce the basic code, which you can then hand-modify and put in your method -- especially if you are using those bar numbers for things like cut, copy, paste. I find that easier than trying to remember the syntax for DEFINE BAR, etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top