poniedziałek, 31 grudnia 2007

Delphi: ENTER zamiast TAB

Klawisz Enter będzie się zachowywał jak TAB.
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
if HiWord(GetKeyState(VK_SHIFT)) <> 0 then
SelectNext(Sender as TWinControl,False,True)
else
SelectNext(Sender as TWinControl,True,True);
Key := #0
end;
end;

i to samo ale w DBGrid
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 Then
begin
if HiWord(GetKeyState(VK_SHIFT)) <> 0 then
begin
with (Sender as TDBGrid) do
if selectedindex > 0 then
selectedindex := selectedindex - 1
else
begin
DataSource.DataSet.Prior;
selectedindex := fieldcount - 1;
end;
end
else
begin
with (Sender as TDBGrid) do
if selectedindex < (fieldcount - 1) then
selectedindex := selectedindex + 1
else
begin
DataSource.DataSet.Next;
selectedindex := 0;
end;
end;
Key := #0
end;
end;

Brak komentarzy: