1. Mark Hulser
  2. PowerBuilder
  3. Thursday, 5 October 2017 17:26 PM UTC

Like many other developers, I have created a user control to be a command button.  Yes, it's because of that whole look-and-feel thing.

Has anyone figured out how to implement the "Default Button" behavior that the system command button allows?

I know I can get the "KeyDown", but isn't that specific to the object that currently has focus?  Is there a better/easier way?

Mark Hulser

Olan Knight Accepted Answer Pending Moderation
  1. Thursday, 5 October 2017 17:40 PM UTC
  2. PowerBuilder
  3. # 1

In your object, have your default option - whether it is YES, NO, or something else - created twice: once as the default option, with thick borders and a shaded perspective, and once as a normal option with normal borders and a normal perspective. Set the option you want to the user to see as VISIBLE and ENABLED, and the other option as NOT VISIBLE and DISABLED.

You can manipulate which version the user sees from within code, as well.



  1. Mark Hulser
  2. Thursday, 5 October 2017 20:30 PM UTC
I understand that from a visual perspective, but I'm looking for the behavior that if the user hits the Enter key, the button (i.e. user control) fires, like a real command button with the "Default" option checked.


  1. Helpful
  1. Olan Knight
  2. Thursday, 5 October 2017 21:33 PM UTC
Oh, in that case you want it to fire only if the object has focus, especially if there are other objects on the window each with their own command buttons.

You've already noted how to do this. In the KEYDOWN event of the object capture the ENTER key and invoke the desired event or function.

Now if you want to do this more globally. or if you have multiple objects each with their own default key, put code in the KEYDOWN event of the WINDOW. When it is triggered, check the object that has focus and invoke the appropriate object.event_or_function.



  1. Helpful
There are no comments made yet.
  • Page :
  • 1

There are no replies made for this question yet.
However, you are not allowed to reply to this question.