The
Then defines an editor, in which all of these editor functions are equivalent to a "bridge" that associates the property with a custom form form. The code is as follows:
///<summary>
///get more from this book, see:
///http://blog.csdn.net/ChengKing/archive/2008/08/18/ 2792440.aspx
///</summary>
public class Calculatorselecteditor: System.Drawing.Design.UITypeEditor
{
Public calculatorselecteditor ()
{
}
Public Overr IDE System.Drawing.Design.UITypeEditorEditStyle GetEditStyle
(System.ComponentModel.ITypeDescriptorContext Context)
{
Return uitypeeditoreditstyle.modal
Public override Object EditValue (System.ComponentModel.ItypeDescriptor
Context Context,system.iserv Iceprovider provider,object value)
{
IWindowsFormsEditorService service = (iwindowsformseditorservice)
Provider. GetService (typeof (IWindowsFormsEditorService));
if (service = = null)
{
return null;
The
Formkeyboard form = new Formkeyboard ();
if (service. ShowDialog (form) = = DialogresulT.ok)
{
Object strreturn = Form.strreturnvalue;
return strreturn;
}
return value;
}
}
The function of this class is to pop up a pattern of the Calculator form form, with the editor function defined in section 4.5.2.2 is almost the same, here is not much to say, if there is no clear place please review the contents of the previous chapters.
Finally, you define the main control code class as follows:
/// <summary>
/// 获得本书更多内容,请看:
/// http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
/// </summary>
[DefaultProperty("Money")]
[ToolboxData("<{0}:CalculatorSelectControl
runat=server></{0}:CalculatorSelectControl>")]
public class CalculatorSelectControl : WebControl
{
[Bindable(true)]
[Category("自定义计算机属性")]
[DefaultValue("")]
[Localizable(true)]
[Editor(typeof(CalculatorSelectEditor),typeof(System.Drawing.Design. UITypeEditor))]
[Description("请输入金额")]
public string Money
{
get
{
string s = (string)ViewState["Money"];
return ((s == null) ? "" : s);
}
set
{
ViewState["Money"] = value;
}
}
//… …
}