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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent cut and paste 1

Status
Not open for further replies.

vanni75

Programmer
Nov 27, 2002
29
BE
Does anybody know how I can prevent Cut and paste from one editbox to an other. I've tried with the keypress method but when the users presses ctrl+v it doesn't go through that method..

Thx in advance

G
 
vanni75

Try in the load of your form

ON KEY LABEL CTRL+V *
ON KEY LABEL CTRL+C *


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Vanni75,

In fact, I think cut and paste are disabled by default within an application. They are only implemented if you have explicitly provided options for them in your menu system (normally by including the appropriate bar numbers in your Edit menu).

I'm not 100 percent sure about that. Maybe someone can confirm?

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike Lewis,

The cut and paste is available without any code. Even SET SYSMENU OFF wont help to avoid this function. Mike Gagnons code will work. By oversight he leftout Ctrl+X for cut..

Vanni..

In the Main.Prg at the beginning along with your SET commands, you can add these codes as well
(if you want to set this or all your forms etc.)

ON KEY LABEL CTRL+V *
ON KEY LABEL CTRL+C *
ON KEY LABEL CTRL+X *

Or as Gagnon said in the init of the form where you want to avoid the cut/copy/paste.

To get back the functions, you have to use the code suitably, somewhere..

ON KEY LABEL CTRL+V
ON KEY LABEL CTRL+C
ON KEY LABEL CTRL+X

:)


____________________________________________
Ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Both Mike's / Ramani

Picking up on this useful thread, how could I incorporate the code in a command button click event to select all the text in a memo field shown on a form for example? I know that CTRL+A refers to select all, but how do you do it as described above?

I suppose I need to ask the obvious as well, if you select all, how do you copy as well? (The paste isn't a concern as this can be done by CTRL+V in another app we ALT+TAB to)

Thanks again in anticipation
Lee (KB)

Alone we can do so little, together we can do so much
 
HI Lee

To capture the whole of what is in an Edit box to clip board, thru a buttons click event.. put the code in that buttons click event

_ClipText = ThisForm.Edit1.Value

That is like selecting All the text and doing a Ctrl+C

:)

____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
vanni75

I suppose I need to ask the obvious as well, if you select all, how do you copy as well? (The paste isn't a concern as this can be done by CTRL+V in another app we ALT+TAB to)

To add to Ramani's suggestion, copy and paste the following in a program and run it.

Code:
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	Top = 0
	Left = 0
	Height = 261
	Width = 645
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	ADD OBJECT edit1 AS editbox WITH ;
		Height = 181, ;
		Left = 24, ;
		Top = 24, ;
		Width = 277, ;
		ControlSource = "mycursor.comments", ;
		Name = "Edit1"
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 216, ;
		Left = 12, ;
		Height = 25, ;
		Width = 85, ;
		Caption = "Select all", ;
		Name = "Command1"
	ADD OBJECT command2 AS commandbutton WITH ;
		Top = 216, ;
		Left = 108, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Copy", ;
		Name = "Command2"
	ADD OBJECT command3 AS commandbutton WITH ;
		Top = 216, ;
		Left = 204, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Paste", ;
		Name = "Command3"
	ADD OBJECT edit2 AS editbox WITH ;
		Height = 181, ;
		Left = 324, ;
		Top = 24, ;
		Width = 289, ;
          	Name = "Edit2"
	PROCEDURE Load
		CREATE CURSOR myCursor (comments M)
		INSERT INTO myCursor (comments) VALUES ("Hello this a comment."+CHR(13)+"You need to select all of this")
		GO top
	ENDPROC
	PROCEDURE command1.Click
		thisform.edit1.SetFocus()
		KEYBOARD '{CTRL+A}' 
	ENDPROC
	PROCEDURE command2.Click
		_ClipText = ThisForm.Edit1.Value
		thisform.edit2.SetFocus()
	ENDPROC
	PROCEDURE command3.Click
		KEYBOARD '{CTRL+V}' 
	ENDPROC
ENDDEFINE

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike / Ramani

Thanks both for your replies.

I have used a combination of both your suggestions and ended up putting the first code in a "Select All" Command Button and the second code in a "Copy Text" Command Button together with a...

=messagebox("Now Use ALT+TAB To Switch Applications and Use CTRL+V to Paste",0+64+0,"System Message")

thisform.edit1.SetFocus()
KEYBOARD '{CTRL+A}'

thisform.edit1.SetFocus()
KEYBOARD '{CTRL+C}'

This works perfect so once again I'm very grateful for your help. Sometimes, the simplist things in life are the easiest!

Take care both

Lee

Alone we can do so little, together we can do so much
 
Sorry the second part should have read

_ClipText = ThisForm.Edit1.Value
thisform.edit1.SetFocus()

This of course is in the "Copy Text" command button click event for all those interested

Lee (KB)

Alone we can do so little, together we can do so much
 
Ramani,

Sorry, I'm coming into this thread a bit late.

The cut and paste is available without any code. Even SET SYSMENU OFF wont help to avoid this function.

No, this is not the case. Without a menu defined for the Copy/Cut/Paste options, they won't work. I just verified this for myself with an app that has these option on the menu. I removed the _med_paste command from the Paste option, and Ctrl+V no longer worked in the app. I put the _med_paste command back, and it worked again.



-BP
 
I've been playing around with this a bit more, and here's some more info on this.

If you don't have any menu options that use Ctrl+C, Ctrl+X and Ctrl+V, then Copy, Cut and Paste will work, whether or not there's a menu option for them. If, however, you have a menu option that uses these as the menu shortcut, that will take precedence over the Copy, Cut and Paste functions.

The reason my experiment worked is because I had Ctrl+V defined as the shortcut for my Paste option. So removing _med_paste from the command disabled the ability for Ctrl+V to paste.



-BP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top