0
A
回答
1
InputQuery()
不適用於這種方式。提示文本應該是顯示在文本字段左側的短標籤(類似於TLabeledEdit
)。它不是爲了在提示之上顯示說明而設計的,就像您正在嘗試的那樣。這種情況可以通過簡單地使用你想要的任何控件和佈局創建你自己的定製表單來處理。例如,使用TDateTimePicker
的日期和時間,TCheckBox
或TRadioGroup
指示重複等
不過,話雖如此,InputQuery()
使用自定義的VCL TForm
實現的,所以它是技術上是可行來完成你是什麼試圖實現。您可以使用TScreen.OnActiveFormChange
事件訪問Form對象,當它變爲可見時,然後您可以根據需要操作它。例如:
procedure TMyForm.ActiveFormChanged(Sender: TObject);
var
Form: TCustomForm;
Prompt: TLabel;
Edit: TEdit;
Ctrl: TControl;
I, J, ButtonTop: Integer;
begin
Form := Screen.ActiveCustomForm;
if (Form = nil) or (Form.ClassName <> 'TInputQueryForm') then Exit;
for I := 0 to Form.ControlCount-1 do
begin
Ctrl := Form.Controls[i];
if Ctrl is TLabel then
begin
Prompt := TLabel(Ctrl);
end
else if Ctrl is TEdit then
begin
Edit := TEdit(Ctrl);
end;
end;
Edit.SetBounds(Prompt.Left, Prompt.Top + Prompt.Height + 5, Prompt.Width, Edit.Height);
Form.ClientWidth := (Edit.Left * 2) + Edit.Width;
ButtonTop := Edit.Top + Edit.Height + 15;
J := 0;
for I := 0 to Form.ControlCount-1 do
begin
Ctrl := Form.Controls[i];
if Ctrl is TButton then
begin
Ctrl.SetBounds(Form.ClientWidth - ((Ctrl.Width + 15) * (2-J)), ButtonTop, Ctrl.Width, Ctrl.Height);
Form.ClientHeight := Ctrl.Top + Ctrl.Height + 13;
Inc(J);
end;
end;
end;
procedure TMyForm.DoSomething;
var
value: string;
begin
Screen.OnActiveFormChange := ActiveFormChanged;
try
InputQuery('Enter New Schedule', 'Format: <Second> <Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week> <Year>.'#10'Use * for repeating cycles. ex: 0 0 7 * * * * (trigger at 7AM everyday)', value);
finally
Screen.OnActiveFormChange := nil;
end;
end;
或者:
class procedure TScreenEvents.ActiveFormChanged(Sender: TObject);
var
Form: TCustomForm;
Instructions: TLabel;
Ctrl: TControl;
I, J, K, Offset: Integer;
begin
Form := Screen.ActiveCustomForm;
if (Form = nil) or (Form.ClassName <> 'TInputQueryForm') then Exit;
for I := 0 to Form.ControlCount-1 do
begin
Ctrl := Form.Controls[I];
if Ctrl is TLabel then
begin
Instructions := TLabel.Create(Form);
Instructions.Parent := Form;
Instructions.Caption := 'Format: <Second> <Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week> <Year>.'#10'Use * for repeating cycles. ex: 0 0 7 * * * * (trigger at 7AM everyday)';
Instructions.SetBounds(Ctrl.Left, Ctrl.Top, Instructions.Width, Instructions.Height);
Offset := Instructions.Top + Instructions.Height + 5;
Form.ClientWidth := Instructions.Width + (Instructions.Left * 2);
K := 0;
for J := 0 to Form.ControlCount-1 do
begin
Ctrl := Form.Controls[J];
if Ctrl <> Instructions then
begin
Ctrl.Top := Ctrl.Top + Offset;
if Ctrl is TEdit then
begin
Ctrl.Width := (Form.ClientWidth - Ctrl.Left - Instructions.Left);
end
else if Ctrl is TButton then
begin
Ctrl.Left := (Form.ClientWidth - (Ctrl.Width + 5) * (2-K));
Inc(K);
end;
end;
end;
Form.ClientHeight := Form.ClientHeight + Offset;
Break;
end;
end;
end;
procedure TMyForm.DoSomething;
var
value: string;
begin
Screen.OnActiveFormChange := ActiveFormChanged;
try
InputQuery('Enter New Schedule', 'Value', value);
finally
Screen.OnActiveFormChange := nil;
end;
end;
相關問題
- 1. XML格式問題
- 2. TinyMce格式問題
- 3. Eclipse格式問題
- 4. jsoncpp格式問題
- 5. css格式問題
- 6. Netbeans格式問題
- 7. NSString格式問題
- 8. Excel格式問題
- 9. JPanel格式問題
- 10. NSPredicate格式問題
- 11. emacs格式問題
- 12. CSS格式問題
- 13. Nsdictionary格式問題
- 14. XSL格式問題
- 15. Streamreader格式問題
- 16. 類格式問題
- 17. 問題格式BoxLayout
- 18. Datagridview格式問題
- 19. NSDateFormatter格式問題
- 20. NSDate格式問題
- 21. wxPython格式問題
- 22. CString。格式問題
- 23. config.xml格式問題
- 24. WPF網格格式問題。
- 25. 單元格格式問題
- 26. HTML表格格式問題
- 27. HTML表格格式問題
- 28. 問題SpeechSynthesizer.SetOutputToAudioStream音頻格式問題
- 29. 格式的原始問題
- 30. xcode4模板格式問題
這不是InputQuery是如何工作的。如果你想要一些不同的東西,創建一個新的表單,然後讓它看起來像你想要的。 (您也可以讓用戶更容易輸入所需的值,而不是讓他們遵循一些神祕而難懂的說明,如果我在這裏完成了類似的操作,我的用戶會開槍。) –
完全同意!這個程序打算供我使用。我只是想知道是否可以使用內置函數節省一些時間。我不需要沒有臭味的輸入驗證:) – ELCouz
爲什麼你需要給自己說明輸入數據的格式,如果它只被你使用?只需將提示改爲*鍵入:*並解決您的問題。在表單上放置標籤,編輯和幾個按鈕需要多長時間?您甚至可以添加一個類函數:'Input:= TMyForm.GetTheText;'它可以創建並顯示錶單並在大約五秒內返回輸入。 –