輸入框
XtraInputBox是一個(gè)可皮膚化的對(duì)話框,它顯示一個(gè)編輯器,供最終用戶設(shè)置所需的值,以及確認(rèn)或拒絕該值的OK/Cancel按鈕。這個(gè)對(duì)話框是XtraDialog控件的簡化版本,具有最少的自定義選項(xiàng)。

提示:輸入框被設(shè)計(jì)為返回用戶輸入的值:要么用戶輸入了一個(gè)值,要么消息被關(guān)閉,返回值為空。這些對(duì)象不返回DialogResult枚舉值,也不允許您識(shí)別用戶單擊了哪個(gè)消息按鈕,如果需要這種行為,請使用XtraDialogs。
輸入框完全由代碼創(chuàng)建和定制,為此,調(diào)用一個(gè)XtraInputBox.Show方法。
使用默認(rèn)的TextEdit編輯器顯示輸入框
要顯示這種類型的輸入框,可以用三個(gè)字符串參數(shù)調(diào)用XtraInputBoxShow方法重載。
參數(shù)名稱 | 描述 |
---|---|
Prompt | 編輯器上方的文本字符串。 |
Title | 對(duì)話框標(biāo)題。 |
DefaultResponse | 當(dāng)輸入框出現(xiàn)在屏幕上時(shí)顯示的默認(rèn)編輯器值。 |
下面的圖像和代碼說明了一個(gè)示例。

C#:
var result = XtraInputBox.Show("Enter a new value", "Change Settings", "Default");
點(diǎn)擊復(fù)制
VB.NET:
Dim result = XtraInputBox.Show("Enter a new value", "Change Settings", "Default")
點(diǎn)擊復(fù)制
當(dāng)最終用戶單擊“OK”時(shí),這個(gè)XtraInputBox.Show方法返回一個(gè)編輯器值。否則,它返回String.Empty。
使用自定義編輯器顯示輸入框
要顯示包含任何DevExpress編輯器的輸入框,請調(diào)用XtraInputBoxShow重載方法,該方法接受XtraInputBoxArgs類的一個(gè)實(shí)例作為參數(shù),XtraInputBoxArgs類公開了以下公共屬性。
屬性 | 描述 |
---|---|
XtraInputBoxArgs.Editor | 輸入框顯示的編輯器 |
XtraInputBoxArgs.DefaultResponse | 當(dāng)輸入框出現(xiàn)在屏幕上時(shí)顯示的默認(rèn)編輯器值。 |
XtraInputBoxArgs.Prompt | 編輯器上方的文本。 |
XtraInputBoxArgs.Showing | 此事件允許訪問和自定義對(duì)話框中的表單。例如,您可以設(shè)置一個(gè)對(duì)話框圖標(biāo)。 |
DefaultButtonIndex | 指定哪個(gè)輸入框按鈕是默認(rèn)的。當(dāng)用戶按下Enter鍵時(shí),默認(rèn)按鈕被認(rèn)為已單擊,將此屬性設(shè)置為0,將“OK”按鈕設(shè)置為默認(rèn)按鈕,或設(shè)置為1來讓“Cancel”按鈕變成默認(rèn)按鈕。 |
Caption | 輸入框標(biāo)題。 |
在下面的圖中,輸入框顯示了一個(gè)日期編輯器。下面的代碼演示了如何創(chuàng)建這樣一個(gè)輸入框。

C#:
private void Args_Showing(object sender, XtraMessageShowingArgs e) { private void Args_Showing(object sender, XtraMessageShowingArgs e) { e.MessageBoxForm.Icon = this.Icon;using DevExpress.XtraEditors; // Initialize a new XtraInputBoxArgs instance XtraInputBoxArgs args = new XtraInputBoxArgs(); // Set required Input Box options args.Caption = "Shipping options"; args.Prompt = "Delivery date"; args.DefaultButtonIndex = 0; args.Showing += Args_Showing; // Initialize a DateEdit editor with custom settings DateEdit editor = new DateEdit(); editor.Properties.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.TouchUI; editor.Properties.Mask.EditMask = "MMMM d, yyyy"; args.Editor = editor; // A default DateEdit value args.DefaultResponse = DateTime.Now.Date.AddDays(3); // Display an Input Box with the custom editor var result = XtraInputBox.Show(args).ToString(); // Set a dialog icon }
點(diǎn)擊復(fù)制
VB.NET:
Imports DevExpress.XtraEditors ' Initialize a new XtraInputBoxArgs instance Dim args As New XtraInputBoxArgs() ' Set required Input Box options args.Caption = "Shipping options" args.Prompt = "Delivery date" args.DefaultButtonIndex = 0 AddHandler args.Showing, AddressOf Args_Showing ' Initialize a DateEdit editor with custom settings Dim editor As New DateEdit() editor.Properties.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.TouchUI editor.Properties.Mask.EditMask = "MMMM d, yyyy" args.Editor = editor ' A default DateEdit value args.DefaultResponse = Date.Now.Date.AddDays(3) ' Display an Input Box with the custom editor Dim result = XtraInputBox.Show(args).ToString() Private Sub Args_Showing(ByVal sender As Object, ByVal e As XtraMessageShowingArgs) e.MessageBoxForm.Icon = Me.Icon End Sub
點(diǎn)擊復(fù)制
當(dāng)最終用戶單擊“OK”時(shí),這個(gè)XtraInputBox.Show方法返回一個(gè)Object,該對(duì)象是編輯器的編輯值。否則,該方法返回null。