The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Disable F2 key
Posted: 12 Sep 06 4:42 PM
|
fiogf49gjkf0d I have a date/time edit that I have set the ButtonVisble property to false, the FormatString property to dddddd, and the kind property to dtk2Date. This works fine, my issue is when that field has focus and the user presses the F2 key, the calendar is still able to be used to populate the field. Is there any way of disabling the F2 key for individual screens or individual fields? |
|
|
|
Re: Disable F2 key
Posted: 13 Sep 06 3:13 PM
|
fiogf49gjkf0d You can use the OnKeyPress event for that control and have it disable based on the Key value. Something like this would work:
Sub OnKeyPress(Sender, ByRef Key) if (Key = 137) then Key = 0 end if End Sub
This checks to make sure they key pressed is F2 (ordinal 137) and by replacing it with 0, the key doesn't register with the control.
You can use this technique for editboxes where you don't want certain keys pressed. For instance, if the FormatType is set to ftInteger and you only want integers to register when typed you would use this:
if (not IsNumeric(Chr(Key))) then Key = 0 end if
|
|
|
|
Re: Disable F2 key
Posted: 13 Sep 06 4:14 PM
|
fiogf49gjkf0d Based on what I have read, the OnKeyPress triggers while no controls have focus and can fire multiple times if the user holds the key. |
|
|
|
Re: Disable F2 key
Posted: 13 Sep 06 5:53 PM
|
fiogf49gjkf0d There's OnKeyPress for the FORM and OnKeyPress for the CONTROL. You want to define the OnKeyPress event of the control you wish to restrict. They can hold F2 down all they want and the control won't respond to it, though the event will be raised repeatedly. As long as you keep the algorithm simple, performance shouldn't be a problem even if people hold down restricted keys. My algorithms do way more than what I gave you and I've yet to notice a performance hit when I hold keys down. |
|
|
|
Re: Disable F2 key
Posted: 25 Sep 06 1:53 PM
|
fiogf49gjkf0d I added the code to disable the F2 key in the OnKeyPress routine and I was still able to access the control after adding the code. I wanted to see if the sub routine was getting called so I also added a message box so it would display when the control was accessed through the F2 key. It appears as if the OnKeyPress sub routine isn't even being called because the message box isn't getting displayed when I access the control by pressing F2. Below is the code for the sub routine:
Sub dtecontractKeyPress(Sender, ByRef Key) msgbox "here" & key if (Key = 137) then Key = 0 end if End Sub |
|
|
|
Re: Disable F2 key
Posted: 25 Sep 06 9:21 PM
|
fiogf49gjkf0d What version of SalesLogix?
This is definitely not "functioning as designed" because the control's OnKeyPress event should trap all keypresses, including ones that modify the control's behavior. This may be outside of SLX's control though as I believe their controls are thin wrappers around Microsoft's.
What about hooking the Form's OnKeyPress event and only disabling F2 for the controls you wish to block? It probably won't work due to the limitations you mentioned (a control can't be in focus) but it's the only thing I can think of barring a service pack or hotfix that addresses the issue specifically. |
|
|
|
Re: Disable F2 key
Posted: 25 Sep 06 9:49 PM
|
fiogf49gjkf0d I believe there are keys that are not captured by the keypress event. I also believe this applies to all 6.x versions (possibly earlier versions too).
The following are examples of keys that do not raise the event: delete, tab, arrow keys, function keys, pageup, home, etc.
Timmus |
|
|
|
Re: Disable F2 key
Posted: 25 Sep 06 10:05 PM
|
fiogf49gjkf0d Bill,
I forgot to mention that you probably just need to set the ReadOnly property to true for the DateTimeEdit. That will prevent the user from launching the popup calendar. Along with the HideButtonIfReadOnly property you should get the behavior you want.
Timmus |
|
|
|