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

Disabling Click, Drag and Copy in an Edit Box

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB
Any suggestions on how to disable click, drag and copy in an edit box on a form without setting enabled=.f. to the edit box. The edit box displays text which in some case the user has to use the scroll bar to view the text. By setting enabled=.f. this disables the scroll bar. I do not want the information shown to be copy and pasted to a document. Hope this makes sense!
I would be extremely grateful for any information....
Kindest Regards.
 
Hi KB,

Code:
DEFINE CLASS CustomEditBox AS EDITBOX

  ilAllowCopy = .T.
  ilAllowCut = .T.

  PROTECTED icCopyCommand,icCutCommand

  icCopyCommand = ''
  icCutCommand = ''

  PROCEDURE GotFocus
    IF ! THIS.ilAllowCopy
      THIS.icCopyCommand=ON('key','ctrl+c')
      ON KEY LABEL CTRL+C *
    ENDIF
    IF ! THIS.ilAllowCut
      THIS.icCutCommand=ON('key','ctrl+x')
      ON KEY LABEL CTRL+X *
    ENDIF
  ENDPROC
  PROCEDURE LostFocus
    IF ! THIS.ilAllowCopy
      lcVar = THIS.icCopyCommand
      ON KEY LABEL CTRL+C &lcVar
    ENDIF
    IF ! THIS.ilAllowCut
      lcVar = THIS.icCutCommand
      ON KEY LABEL CTRL+V &lcVar
    ENDIF
  ENDPROC
ENDDEFINE

In a nutshell, just store/restore the ctrl+c & ctrl+x key labels in the gotfocus/lostfocus events of your control. Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
In addition to Jon's sample for keys, following is a way how to disable drag and drop:

Put transparent container or shape over the box portion of the edit box. User will be able to scroll edit box, but all mouse clicks will go to transparent object over the edit box. If edit box 'go up' and drops off transparent shape, put timer on form and constantrly use 'ZORDER' method for transparent object to assure it is always on top over the edit box.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top