Re: Feature Request - "Snap To" default button



MJMatthew wrote:

This problem applies to Delphi itself, plus any written applications.

It's because of the class name of buttons in Delphi are not "Button".

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

procedure MouseSnapTo(AForm: TForm);
var
i: integer;
Button: TButton;
Pt: TPoint;
Snap: integer;
begin
SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0, @Snap, 0);
if Snap > 0 then
for i := 0 to AForm.ComponentCount - 1 do
if AForm.Components[i] is TButton then
begin
Button := AForm.Components[i] as TButton;
if Button.Default then
begin
Pt.X := Button.Left + (Button.Width div 2);
Pt.Y := Button.Top + (Button.Height div 2);
Pt := AForm.ClientToScreen(Pt);
SetCursorPos(Pt.X, Pt.Y);
end;
end;
end;

eg:

procedure TForm1.FormShow(Sender: TObject);
begin
MouseSnapTo(Self);
end;

--
Dave Nottage [TeamB]
.