using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Globalization; using System.Reflection; using System .Windows.forms; using system.windows.forms.design; using system.drawing.design;
Namespace TestinstanceDescriptor {
[TypeConverter]] public class mysize {private int _x, _y; public readonly static mysize empty
Static mysize () {empty = new mysize ();
Public mysize () {}
Public mysize (int x, int y) {_x = x; _y = y;
Public int x {get {return _x;} set {_x = value;}}
Public int y {get {return _y;} set {_y = value;}}
Public override string toString () {Return String.Format ("{0}, {1}", _ x.toString (), _ y.toString ());}}
public class MySizeTypeConverter: TypeConverter {public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType) {if (sourceType == typeof (string)) return true; else return base.CanConvertFrom (context, sourceType);}
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) {if (destinationType == typeof (string) || destinationType == typeof (InstanceDescriptor)) return true; else return base.CanConvertTo (context, destinationType);}
public override object ConvertFrom (ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {if (value == null) {return null;} if (! (value is string)) {return base.ConvertFrom (context, culture, Value);} String str = (String) Value) .trim (); if (str.Length == 0) {RETURN MYSIZE.EMPTY;} char [] splitchar = {','}; String [] VALUES = (String) Value) .split (splitchar); if (Values.Length! = 2) Return mysize.empty; try {int x = convert.Toint32 (VALUES [0]); int y = convert.Toint32 (VALUES [ 1]); MySize s = new MySize (); sX = x; sY = y; return s;} catch (FormatException) {return MySize.Empty;}} public override object ConvertTo (ITypeDescriptorContext context, System.Globalization.CultureInfo culture , Object value, Type destinationType) {if (destinationTYPE == typeof (instancedescriptor)) {mysize o = (mysize) value; type intertys = typeof (int); memberInfo mi = typeof (mysize) .Getconstructor (new type {INTTYPE, INTTYPE}); Object [] args = new object [] {ox, oo}; return new instancedescriptor (mi, args);} if (destinationType! = Typeof (string) { Return Base.convertTo (Context, Culture, Value, DestinationType);} if (value! = null) {mysize size = (mysize) value; if (size! = mysize.empty) Return size.toString ();} return string }}
///
Public class mysizeeditor: uitypeEditor {public override uitypeEditoreditStyle getEDitstyle (iTYPEDEScriptorContext context) {return uitypeeditorEditStyle.dropdown;}
public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value) {IWindowsFormsEditorService wfe = (IWindowsFormsEditorService) provider.GetService (typeof (IWindowsFormsEditorService)); MySize o = (MySize) value;
IF (wfe! = null) {labelcomponiteneditorform form = new labelcomponiteneditorform (OX, OY); Using (Form) {wfe.dropdownControl (form); return.com; form.x, form.y);}}}}} Return Base.editValue (Context, Provider, Value);
}
public class LabelComponentEditorForm: System.Windows.Forms.UserControl //System.Windows.Forms.Form {private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1 ;
Private system.windows.forms.label label2; private system.windows.forms.textbox textbox2; public int x {get {return convert.Toint32 (THISTBOX1.TEXT);}}
Public int y {get {return control.Toint32 (THISTEXTBOX2.TEXT);}}} ///
// // Todo: Add any constructor code after INITIALIZEComponent call //}
Public labelcomponiteneditorform (int x, int y): this () {this.textBox1.text = x.toString (); this.textbox2.text = y.to tring ();}
///
#REGION Windows Form Designer The code ///
/// summary> private vid initializecomponent () {this.label1 = new system.windows.forms.label (); this.textbox1 = new system.windows.forms.textbox (); this.button1 = new system. Windows.Forms.Button (); this.Label2 = new system.windows.forms.label (); this.textbox2 = new system.windows.forms.textbox (); this.suspendlayout (); // // label1 / / This.label1.location = new system.drawing.point (8, 16); this.label1.name = "label1"; this.label1.size = new system.drawing.size (88, 24); this.label1 .Tabindex = 0; this.label1.text = "Please enter the prompt x:"; // // textbox1 // this.textbox1.location = new system.drawing.point (96, 14); this.TextBox1.name = "TextBox1"; this.textBox1.size = new system.drawing.size (112, 21); this.textBox1.tabindex = 1; this.TextBox1.text = ""; // button1 // this.button1. Location = new system.drawing.point (120, 80); this.button1.name = "button1"; this.button1.size = new system.drawing.size (80, 24); this.button1.tabindex = 2; this.button1.text = "ok"; this.button1.click = new system.eventhandler (this.button1_click); // // label2 // this.label2.location = new system.drawing.point (8 , 48); this.label2.name = "label2"; this.label2.size = new system.drawing.size (88, 24); this.label2.tabindex = 0; this.Label2.text = "Please enter a prompt Y: "; /// textBox2 // this.textBox2.Location = new system.drawing.point (96, 48); this.textBox2.name =" textbox2 "; this.textbox2.size = new system.drawing. Size (112, 21); this.TextBox2.tabindex =
1; this.textBox2.text = ""; // // LabelcomponiteTeditorForm /////His.AutoscaleBasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (216, 114 This.Controls.add (this.button1); this.Controls.add (this.TextBox1); this.controls.add (this.label1); this.controls.add (this.label2); this.controls. Add (this.textBox2); //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.Name = "LabelComponentEditorForm"; this.Text = "Form1"; this.ResumeLayout (false);} #endregion
Private void button1_click (object sender, system.eventargs e) {//this.close ();}}}