输入框
XtraInputBox是一个可皮肤化的对话框,它显示一个编辑器,供最终用户设置所需的值,以及确认或拒绝该值的OK/Cancel按钮。这个对话框是XtraDialog控件的简化版本,具有最少的自定义选项。
提示:输入框被设计为返回用户输入的值:要么用户输入了一个值,要么消息被关闭,返回值为空。这些对象不返回DialogResult枚举值,也不允许您识别用户单击了哪个消息按钮,如果需要这种行为,请使用XtraDialogs。
输入框完全由代码创建和定制,为此,调用一个XtraInputBox.Show方法。
使用默认的TextEdit编辑器显示输入框
要显示这种类型的输入框,可以用三个字符串参数调用XtraInputBoxShow方法重载。
| 参数名称 | 描述 |
|---|---|
| Prompt | 编辑器上方的文本字符串。 |
| Title | 对话框标题。 |
| DefaultResponse | 当输入框出现在屏幕上时显示的默认编辑器值。 |
下面的图像和代码说明了一个示例。
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编辑器的输入框,请调用XtraInputBoxShow重载方法,该方法接受XtraInputBoxArgs类的一个实例作为参数,XtraInputBoxArgs类公开了以下公共属性。
| 属性 | 描述 |
|---|---|
| XtraInputBoxArgs.Editor | 输入框显示的编辑器 |
| XtraInputBoxArgs.DefaultResponse | 当输入框出现在屏幕上时显示的默认编辑器值。 |
| XtraInputBoxArgs.Prompt | 编辑器上方的文本。 |
| XtraInputBoxArgs.Showing | 此事件允许访问和自定义对话框中的表单。例如,您可以设置一个对话框图标。 |
| DefaultButtonIndex | 指定哪个输入框按钮是默认的。当用户按下Enter键时,默认按钮被认为已单击,将此属性设置为0,将“OK”按钮设置为默认按钮,或设置为1来让“Cancel”按钮变成默认按钮。 |
| Caption | 输入框标题。 |
在下面的图中,输入框显示了一个日期编辑器。下面的代码演示了如何创建这样一个输入框。
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
}
点击复制
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
点击复制
当最终用户单击“OK”时,这个XtraInputBox.Show方法返回一个Object,该对象是编辑器的编辑值。否则,该方法返回null。

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线