我在窗体中添加了如下功能,以方便用户可以用方向键在不同的输入框中进行填写.
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
vk_up: SendMessage(Handle,WM_NEXTDLGCTL,1,0);
vk_down: SendMessage(Handle,WM_NEXTDLGCTL,0,0);
end;
end;但现在我想在窗体上再加入ComboBox组件.每次聚焦在ComboBox中后,用上、下方向键进行ComboBox下拉列表中选项的选择时,焦点却移动至下一个组件,?怎样才能在ComboBox中将FormKeyDown的功能屏蔽掉,以进行ComboBox下拉列表中选项的选择?请各位前辈指教一二。 谢谢!
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
vk_up: SendMessage(Handle,WM_NEXTDLGCTL,1,0);
vk_down: SendMessage(Handle,WM_NEXTDLGCTL,0,0);
end;
end;但现在我想在窗体上再加入ComboBox组件.每次聚焦在ComboBox中后,用上、下方向键进行ComboBox下拉列表中选项的选择时,焦点却移动至下一个组件,?怎样才能在ComboBox中将FormKeyDown的功能屏蔽掉,以进行ComboBox下拉列表中选项的选择?请各位前辈指教一二。 谢谢!
如果你那可以的话有很多总方法,if TComboBox(sender) = Cbname then
Form1.KeyPreview:=True;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not (ActiveControl = cbb1) then
begin
case Key of
vk_up: SendMessage(Handle,WM_NEXTDLGCTL,1,0);
vk_down: SendMessage(Handle,WM_NEXTDLGCTL,0,0);
end;
end;
end;
begin
ComboBox1.DroppedDown := true;
Key := 0;
end
Else
begin
Sender.Perform(WM_NEXTDLGCTL, 0, 0);
Key := 0;
end;
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if ComboBox1.DroppedDown then Exit; case Key of
vk_up: SendMessage(Handle,WM_NEXTDLGCTL,1,0);
vk_down: SendMessage(Handle,WM_NEXTDLGCTL,0,0);
end;
end;