Avoid return/enter key in a DesktopDateTimePicker?

How can I avoid the user from using the Enter/Return/Tab key in a DesktopDateTimePicker object?

I have added the Key Down event to the object and added this code, but hitting the Return/Tab Key still changes the focus to another text field.

The Tab Index Focus Control of the DesktopDateTimePicker object is set to 0.

If key = chr(13) Or key = chr(3) or key = chr(9) Then 
  return false
  
end if

False is the standard return value of the KeyDown event, meaning “do not intercept the control from processing this event”.
Return True instead.

Ah I see, I didn’t know that. It works now, thanks Ulrich.

1 Like

I think that Ulrich statement is a bit confuse for some people, I think that a better way to express what he wanted to say is: “True” means “I processed the event as I wished, no default processing of this event is necessary after I return it”. So, if true is returned, and the event is a key event, for example, the system won’t process such key, as you instructed it that you already did it. So the “false” (and default) is the other way around, it’s a “dear framework, process such event (and key in this case) as usual”.

It is confusing, yes. I read it now as if Return = true, then don’t let the command do its work. So a Return key will not commit and a tab key will not jump to another field. But I would have expected this with the False status.

The internals are just kind of

Function FrameworkProcessEvent()
  
  If UserProcessEvent() Then    // a call to your user event code
    
    // Returned True, Do nothing
    
  Else
    
    DoTheDefaultEventProcessing()  // Returned false. Process key, mouse, etc
    
  End
  
End Function