Mega Code Archive

 
Categories / Delphi / Forms
 

Activate de default button

Title: Activate de default button Question: Here it is a simple procedure that will make the first default button off a form focused and the mouse pointer centered in it Answer: procedure ActivateDefBtn(Focus, Mouse: Boolean); var i: Integer; pt: TPoint; begin for i := 0 to ComponentCount - 1 do if Components[i] is TButton then with TButton(Components[i]) do if Default then begin if Focus then SetFocus; if Mouse then begin pt.X := Left; pt.Y := Top; pt := Self.ClientToScreen(pt); SetCursorPos(pt.X + Width div 2, pt.Y + Height div 2); end; Break; end; end; you can call this routine, for example, OnFormShow event of your form.