Announcement

Collapse
No announcement yet.

Default Button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Default Button

    Sorry, very basic question but can't find answer - how do I set the default button then will be activated if the enter key is pressed.
    Brent Boshart

  • #2
    When you create the selected button use the %BS_DEFAULT style
    in the window style. If using DDT as follows :
    Code:
      Control Add Button, FindDlg, %btnSearch, "Find", 15, 95, 45, 12,%BS_DEFAULT,

    Comment


    • #3
      And after the controls are created using DDT, how would I change which button is default? Thats what I'm really after, sorry I should have explained myself better.

      [This message has been edited by Brent Boshart (edited January 26, 2000).]
      Brent Boshart

      Comment


      • #4
        Brent --
        "Default" means that a button has a focus. To move focus use
        Control Set Focus hDlg&, Id&

        Comment


        • #5
          %BS_DEFAULT is the same as %BS_DEFPUSHBUTTON. The button with this style is "pressed" when the ENTER key is pressed, even if FOCUS in on another control. Therefore, Semen, changing focus does not change the default button for the ENTER key (it does affect the action of the SPACE key).

          CONTROL SET FOCUS is a generic function designed to work with all [DDT] controls, so it does not update the appearance of buttons when focus is set. Try this small substitute sub to change focus and default button at the same time:
          Code:
          SUB ButtonSetFocus(BYVAL hDlg AS LONG, BYVAL CtlId AS LONG)
             CONTROL SET FOCUS hDlg, CtlId
             CONTROL SEND hDlg, CtlId, %BM_SETSTYLE, %BS_DEFPUSHBUTTON, %TRUE
          END SUB
          If another button already has a dark border around it, this sub will not change that, so you will have to send the "old" button a message to clear it:
          Code:
          CONTROL SEND hDlg, CtlId, %BM_SETSTYLE, %BS_PUSHBUTTON, %TRUE
          -------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Lance --
            you are right (about space & enter).
            Thanks for useful information [smile]

            Comment


            • #7
              Thanks, works great.

              [This message has been edited by Brent Boshart (edited January 26, 2000).]
              Brent Boshart

              Comment

              Working...
              X