配接器設定的自訂下拉式編輯器
自訂編輯器的程式碼會顯示衍生自 System.Drawing.Design.UITypeEditor 類別的編輯器,該類別會顯示用於輸入密碼的下拉式文字方塊。 GetEditStyle覆寫會傳回UIEditorEditStyle.DropDown來表示下拉式子控制項。 DropDownControl和CloseDropDown服務方法會管理使用CreatePassword建立的控制項。
下列程式碼為此自訂下拉式編輯器的類別定義:
/*************************************************************************
* Copyright (c) 1999-2004 Microsoft Corporation. All rights reserved. *
* *
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY *
* KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE *
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR *
* PURPOSE. THE ENTIRE RISK OF USE OR RESULTS IN CONNECTION WITH THE USE *
* OF THIS CODE AND INFORMATION REMAINS WITH THE USER. *
*************************************************************************/
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Security;
using System.Security.Permissions;
using Microsoft.BizTalk.Adapter.Framework;
using Microsoft.BizTalk.Adapter.Framework.Forms;
namespace AdapterManagement.ComponentModel {
/// <summary>
/// PasswordUITypeEditor implements a user interface for acquiring passwords
/// within a visual designer.
/// </summary>
public class PasswordUITypeEditor : UITypeEditor {
public const char PasswordChar = '\u25cf';
private IWindowsFormsEditorService _service = null;
private TextBox _password = null;
[SecurityPermissionAttribute(SecurityAction.LinkDemand)]
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
if (null != context && null != context.Instance) {
return UITypeEditorEditStyle.DropDown;
}
return base.GetEditStyle(context);
}
[SecurityPermissionAttribute(SecurityAction.LinkDemand)]
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider,
object value) {
if (null != context && null != context.Instance && null != provider) {
this._service = (IWindowsFormsEditorService) provider.GetService
(typeof(IWindowsFormsEditorService));
if (null != this._service) {
this._password = CreatePassword();
this._service.DropDownControl(this._password);
value = this._password.Text;
}
}
return value;
}
private TextBox CreatePassword () {
TextBox password = new TextBox();
password.PasswordChar = PasswordUITypeEditor.PasswordChar;
password.Leave += new EventHandler(password_Leave);
}
private void password_Leave(object sender, EventArgs e) {
if (null != this._service) {
this._service.CloseDropDown();
}
}
} // PasswordUITypeEditor
} // Microsoft.BizTalk.Adapter.Framework.ComponentModel