文档首页>>DevExpress WinForm中文手册>>输入框(inputbox)
输入框(inputbox)
XtraInputBox是一个外观化对话框,显示一个用于最终用户设置所需值的编辑器,用OK/Cancel按钮来确认或拒绝该值。该对话框是XtraDialog控件的简化版本,带有最少的自定义选项。

输入框完全由代码创建和自定义,因此请调用XtraInputBox.Show方法。
显示带有默认TextEdit编辑器的输入框
若要显示此类型的输入框,请使用三个字符串参数调用XtraInputBox.Show方法重载。
- Prompt - 编辑器上方的文本字符串。
- Title - 对话框标题。
- DefaultResponce - 当屏幕上出现输入框时显示的默认编辑器值。
下面的图像和代码演示了一个示例。

C#
var result = XtraInputBox.Show("Enter a new value", "Change Settings", "Default");
VB.NET
Dim result = XtraInputBox.Show("Enter a new value", "Change Settings", "Default")
当最终用户单击"OK"时,此XtraInputBox.Show方法返回编辑器值,否则返回String.Empty。
使用自定义编辑器显示输入框
要显示带有任何DevExpress编辑器的输入框,请调用XtraInputBox.Show方法重载,该重载将XtraInputBoxArgs类的实例作为参数,XtraInputBoxArgs类公开以下公共属性。
- XtraInputBoxArgs.Editor - 输入框显示的编辑器。
- XtraInputBoxArgs.DefaultResponse - 当屏幕上出现输入框时显示的默认编辑器值。
- XtraInputBoxArgs.Prompt - 编辑器上方的文本。
- XtraInputBoxArgs.Showing - 此事件使您可以访问和自定义对话框中的表单, 例如您可以设置一个对话框图标。
- DefaultButtonIndex - 指定哪个输入框按钮是默认按钮。 当最终用户按下Enter键时,默认按钮被视为已单击。 将此属性设置为0,使 "OK"成为默认按钮,而将“ 1”设为“Cancel”按钮。
- Caption - 输入框标题。
在下图输入框显示DateEdit编辑器,下面的代码说明了如何创建这种输入框。

C#
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 private void Args_Showing(object sender, XtraMessageShowingArgs e) { e.Form.Icon = this.Icon; }
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.Form.Icon = Me.Icon End Sub
当最终用户单击"OK"时,此 XtraInputBox.Show方法将返回一个对象,该对象是编辑器的编辑值,否则该方法返回null。