Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/IDE/Form Designer    [ Add a report in this area ]  
Report #:  41560   Status: Reported
Snap To default button
Project:  Delphi Build #:  10.0.2288.42451
Version:    10.0 Submitted By:   Matthew Marsh
Report Type:  New Feature Request Date Reported:  3/1/2007 2:20:09 AM
Severity:    Commonly encountered problem Last Updated:
Platform:    All platforms Internal Tracking #:  
Resolution: None  Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
5.00 out of 5
Total Votes: 11
Delphi applications do not utilise the "Snap To" feature built into Windows, where the mouse cursor jumps to the default button.

This is located in:  Start / Control Panel / Mouse / Pointer Options / Snap

I appreciate that this is isn't the most important thing in life, but this
type of thing creates confusion. You have forms that don't pick up the Snap-To setting, whilst dialogs do.

What's the difference ?. I would have thought that any form or dialog with an OK or Cancel button should implement the Snap-To feature automatically.

It doesn't matter if you like this feature it or not. By default it is switched off anyway. But for those people that do switch it on, then I
believe it should apply globally.

Steps to Reproduce:
Not applicable.
Provided by TeamB members: Dave Nottage and Remy Lebeau

> Expanding on my other post, you could call this function in the
> event of the form:

That code does not check for buttons that have a different Parent than
the Form itself.  You would need a recursive search for that, ie:

    function FindDefaultButton(AParent: TWinControl): TButton;
        I: Integer;
        Ctrl: TControl;
        Result := nil;
        for I := 0 to AParent.ControlCount-1 do
            Ctrl := AParent.Controls[I];
            if (Ctrl is TButton) and TButton(Ctrl).Default then
                Result := TButton(Ctrl);
            if Ctrl is TWinControl then
                Result := FindDefaultButton(TWinControl(Ctrl));
                if Result <> nil then Exit;

    procedure MouseSnapTo(AForm: TForm);
        Snap: Integer;
        Button: TButton;
        Pt: TPoint;
        SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0, @Snap, 0);
        if Snap > 0 then
            Button := FindDefaultButton(AForm);
            if Button <> nil then
                Pt := Button.ClientOrigin;
                Inc(Pt.X, Button.ClientWidth div 2);
                Inc(Pt.Y, Button.ClientHeight div 2);
                Windows.SetCursorPos(Pt.X, Pt.Y);

Jeremy North at 3/1/2007 3:02:01 AM -
The workaround should also check to see if the button is visible and enabled

Server Response from: ETNACODE01