輸入框
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交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線