Interaction.InputBox(String, String, String, Int32, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在對話框中顯示提示,等待使用者輸入文字或點擊按鈕,然後回傳包含文字框內容的字串。
public static string InputBox(string Prompt, string Title = "", string DefaultResponse = "", int XPos = -1, int YPos = -1);
static member InputBox : string * string * string * int * int -> string
Public Function InputBox (Prompt As String, Optional Title As String = "", Optional DefaultResponse As String = "", Optional XPos As Integer = -1, Optional YPos As Integer = -1) As String
參數
- Prompt
- String
必要 String 表達式會以對話框中的訊息形式顯示。 最大 Prompt 長度約為 1024 個字元,視所用字元的寬度而定。 如果 Prompt 包含多行,你可以用換行字元(Chr(13))、換行字元(Chr(10))或換行/換行組合(Chr(13) 和 Chr(10))來分隔行。
- Title
- String
Optional.
String 表達式顯示在對話框的標題欄中。 如果你省略 Title了,申請名稱會放在標題欄。
- DefaultResponse
- String
Optional.
String 若無其他輸入,則在文字框中顯示為預設回應。 如果你省略 DefaultResponse了 ,顯示的文字框會是空的。
- XPos
- Int32
Optional. 數值表達式,以 twips 表示對話框左邊與螢幕左邊的距離。 如果你省略 XPos了,對話框會橫置於中央。
- YPos
- Int32
Optional. 數值表達式,以 twips 表示對話框上緣與螢幕頂端的距離。 如果省略 YPos,對話框會垂直排列,約在螢幕下方三分之一處。
傳回
在對話框中顯示提示,等待使用者輸入文字或點擊按鈕,然後回傳包含文字框內容的字串。
範例
此範例展示了多種使用 InputBox 該函式提示使用者輸入數值的方法。 若省略 x 與 y 位置,對話框會自動置中對應軸。 變數 MyValue 包含使用者在點擊確定或按下 ENTER 鍵時所輸入的值。
Dim message, title, defaultValue As String
Dim myValue As Object
' Set prompt.
message = "Enter a value between 1 and 3"
' Set title.
title = "InputBox Demo"
defaultValue = "1" ' Set default value.
' Display message, title, and default value.
myValue = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If myValue Is "" Then myValue = defaultValue
' Display dialog box at position 100, 100.
myValue = InputBox(message, title, defaultValue, 100, 100)
' If user has clicked Cancel, set myValue to defaultValue
If myValue Is "" Then myValue = defaultValue
備註
如果使用者點擊 取消,會回傳一個長度為零的字串。
若要指定超過第一個參數,必須在表達式中使用該 InputBox 函數。 若省略任何位置論元,必須保留相應的逗號分隔符。
備註
InputBox函式在層級需要 SafeTopLevelWindowsUIPermission ,這可能會影響其在部分信任情況下的執行。 欲了解更多資訊,請參閱 請求權限 及 UIPermission 。