Designtime Property Setting outside propertylist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have this custom control (derived from a TextBox) with a property. I find it bothersome to go through the (long) property list to set a simple, (for me most important) property in the property list.

So, I created a custom designer, and when I right-click the control I get a popup menu, where I can select my value. Works fine.

But, if I use the popupmenu_click handle to set the property, it doesn't get serialized on saving. Instead, the value saved is still from the property list, so that's the old value....

Now, how do I get the property list to update and reflect the new value?
Do I have to create an editor, and capture some MyPropertyChanged event, and then set it in the editor?

Currently I have the code like below.

class MyTextBox : TextBox
{
private string myProperty

public string MyProperty
{ get { return this.myProperty; } set { this.myProperty = value; }

.....

protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
if(this.DesignMode)
{
ContextMenu contextMenu = new ContextMenu()
...
contextMenu.Show(this, new Point(e.X, e.Y));
}
}

public void MenuItem_Click(object sender, System.EventArgs e)
{
this.MyProperty = (e as MenuItem).Text
}
 
FYI: I solved it, thanks to this link:

http://www.windowsforms.com/Forums/ShowPost.aspx?tabIndex=1&tabId=41&PostID=17562

The designer now responses to a MyPropertyChanged event, and uses this code:

IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));

c.OnComponentChanging(this.myControl, null);
this.myControl.MyProperty = e.MyProperty;
c.OnComponentChanged(this.myControl, null, null, null);

(this.myControl is set in the constructor of the designer)

Thanks all
Ronald
 
Back
Top