Hi dilipkumarmdk,
You can inherited from UITypeEditor to extend its function.
Here is the code.
| publicclassMyTextBox:TextBox |
| { |
| privatestringmyItem; |
| |
| publicMyTextBox() |
| { |
| } |
|
| [Editor("WindowsFormsApplication1.MyItemEditor",typeof(UITypeEditor))] |
| publicstringMyItem |
| { |
| get{returnmyItem;} |
| set{myItem=value;} |
| } |
| } |
The extended UITypeEditor of MyItem property
| publicclassMyItemEditor:UITypeEditor |
| { |
| privateobjecteditorService; |
| privateobjectreturnValue; |
|
| publicMyItemEditor():base() |
| { |
| } |
|
| publicoverrideUITypeEditorEditStyleGetEditStyle(ITypeDescriptorContextcontext) |
| { |
| returnUITypeEditorEditStyle.Modal; |
| } |
|
| publicoverrideobjectEditValue(ITypeDescriptorContextcontext,IServiceProviderprovider,objectvalue) |
| { |
| if(provider!=null) |
| { |
| editorService=provider.GetService(typeof(IWindowsFormsEditorService)); |
| } |
| if(editorService!=null) |
| { |
| MyItemEditorFormmyForm=newMyItemEditorForm(value,(IWindowsFormsEditorService)editorService); |
| ((IWindowsFormsEditorService)editorService).ShowDialog(myForm); |
| //ThetextBox1onMyItemEditorFormispublic |
| //SoIcanaccessitdirectly. |
| returnValue=myForm.textBox1.Text; |
| |
| } |
| returnreturnValue; |
| } |
| } |
Then here is the form that have one OK button and a TextBox
| publicpartialclassMyItemEditorForm:Form |
| { |
| privateobjecteditor; |
| privateIWindowsFormsEditorServiceeditorService; |
|
| publicMyItemEditorForm() |
| { |
| InitializeComponent(); |
| } |
|
| publicMyItemEditorForm(objecteditorValue,IWindowsFormsEditorServiceeditorService) |
| { |
| InitializeComponent(); |
| this.editor=editorValue; |
this.editorService=editorService; this.textBox1.Text = (string)editorValue; |
| } |
|
| privatevoidbtnOK_Click(objectsender,EventArgse) |
| { |
| this.Close(); |
| } |
| } |
Notice: on this form, I have added a TextBox(textBox1) and a Button(OK), I have set the Modifiers property of textBox1 to public so it can be access outside form.
If you have any question, please feel free to tell me.
Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.