upon form show, if no activecontrol, then focus first control in tab order

git-svn-id: trunk@5851 -
This commit is contained in:
micha 2004-08-25 17:59:06 +00:00
parent 02624f0d07
commit 171e00f7b4
2 changed files with 30 additions and 2 deletions

View File

@ -362,6 +362,29 @@ end;
ShowWindow event handler.
------------------------------------------------------------------------------}
procedure TCustomForm.WMShowWindow(var message: TLMShowWindow);
function FindFirstControl: TWinControl;
var
List: TList;
I: Integer;
begin
List := TList.Create;
Result := nil;
try
GetTabOrderList(List);
for I := 0 to List.Count - 1 do
begin
if TObject(List.Items[0]) is TWinControl then
begin
Result := TWinControl(List.Items[0]);
exit;
end;
end;
finally
List.Free;
end;
end;
begin
{$IFDEF VerboseFocus}
DbgOut('TCustomForm.WMShowWindow A ',Name,':',ClassName,' fsShowing=',fsShowing in FFormState,' Msg.Show=',Message.Show);
@ -376,6 +399,8 @@ begin
Include(FFormState, fsShowing);
try
if Message.Show then begin
if FActiveControl = nil then
FActiveControl := FindFirstControl;
if (FActiveControl<>nil) and FActiveControl.HandleAllocated
and (FActiveControl.Visible) and (FActiveControl.Enabled) then begin
{$IFDEF VerboseFocus}
@ -1754,6 +1779,9 @@ end;
{ =============================================================================
$Log$
Revision 1.153 2004/08/25 17:59:06 micha
upon form show, if no activecontrol, then focus first control in tab order
Revision 1.152 2004/08/18 20:49:02 mattias
simple forms can now be child controls

View File

@ -90,8 +90,8 @@ begin
TabOrder := 2;
end;
// upon show, focus the edit control so people can start typing
ActiveControl := Edit;
// upon show, the edit control will be focused for editing, because it's
// the first in the tab order
If ShowModal = mrOk then
begin
Value := Edit.Text;