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
Description
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
To.

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.

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

> Expanding on my other post, you could call this function in the
OnShow
> 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;
    var
        I: Integer;
        Ctrl: TControl;
    begin
        Result := nil;
        for I := 0 to AParent.ControlCount-1 do
        begin
            Ctrl := AParent.Controls[I];
            if (Ctrl is TButton) and TButton(Ctrl).Default then
            begin
                Result := TButton(Ctrl);
                Exit;
            end;
            if Ctrl is TWinControl then
            begin
                Result := FindDefaultButton(TWinControl(Ctrl));
                if Result <> nil then Exit;
            end;
        end;
    end;

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

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