[英]How to move a panel or frame by dragging it or any component inside it?
[英]How to move to the next control inside a frame?
在我的應用程序的一種形式中,我們通過向表單添加框架來添加數據集。 對於每個幀,我們希望能夠通過按Enter鍵從一個編輯(Dev Express Editors)控件移動到下一個控件。 到目前為止,我已經在我的控件的KeyPress和KeyUp事件中嘗試了四種不同的方法。
SelectNext(TcxCurrencyEdit(Sender), True, True); // also base types attempted
SelectNext(Sender as TWinControl, True, True);
Perform(WM_NEXTDLGCTL, 0, 0);
f := TForm(self.Parent); // f is TForm or my form c := f.FindNextControl(f.ActiveControl, true, true, false); // c is TWinControl or TcxCurrencyEdit if assigned(c) then c.SetFocus;
這些方法都不適用於Delphi 5.任何人都可以指導我使用它嗎? 謝謝。
當用戶按下Enter鍵然后它觸發VK_TAB
鍵時,我找到了一個捕獲CM_DIALOGKEY
消息的舊項目。 它適用於許多不同的控件。
interface
...
procedure CMDialogKey(var Message: TCMDialogKey);message CM_DIALOGKEY;
implementation
...
procedure TSomeForm.CMDialogKey(var Message : TCMDialogKey);
begin
case Message.CharCode of
VK_RETURN : Perform(CM_DialogKey, VK_TAB, 0);
...
else
inherited;
end;
end;
這適用於Delphi 3,5和6:
將表單的KeyPreview屬性設置為True。
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
If (Key = #13) then
Begin
SelectNext(ActiveControl as TWinControl, True, True);
Key := #0;
End;
end;
事件onKeyPress像任何其他形式一樣被觸發。
問題是程序執行(wm_nextdlgctl,0,0)在框架內不起作用。
您必須知道主動控件才能使正確的事件發生變化。
procedure TFrmDadosCliente.EditKeyPress(Sender: TObject; var Key: Char);
var
AParent:TComponent;
begin
if key = #13 then
begin
key := #0;
AParent:= TComponent(Sender).GetParentComponent;
while not (AParent is TCustomForm) do
AParent:= AParent.GetParentComponent;
SelectNext(TCustomForm(AParent).ActiveControl, true, true);
end;
end;
您可以在表單上放置TButton,將其縮小並將其隱藏在其他控件下。 將Default屬性設置為true(使其獲得Enter鍵)並將以下內容放入OnClick事件:
SelectNext(ActiveControl, true, true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.