Windows Develop Bookmark and Share   
 index > Windows Forms Designer > how to open a form when click on custom property item in propertygridview
 

how to open a form when click on custom property item in propertygridview

i am adding one custom property to textbox.when i click on this item i need to show one form (like popup window).and this form having one textbox and one button..after entering the text in textbox and click on ok button.i need to display the text in this custom property item..

please any one help me.

Regards..

Dilip


dilipkumarmdk  Friday, March 06, 2009 3:24 AM

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.
Kira Qian  Monday, March 09, 2009 9:05 AM

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.
Kira Qian  Monday, March 09, 2009 9:05 AM

You can use google to search for other answers

Custom Search

More Threads

• drag-and-drop,resize,and moving controls in runtime
• Problem in DoDragDrop in Custom form Designer on DotNet 2.0.
• Implement Drag & Drop and Mouse Events
• DesignMode at non-control components
• Problem with setting SplitContainer.SplitterDistance at runtime
• expandable property in property window
• Collection Editor only shows Object
• How can I set the Scrollbar Color for a TreeView?
• Resize a panel
• How to show a context menu for a component in a designer host?