StatusBarPanel: Parent property not cleared

G

Glenn Nilsson

Hi,

I want to add and remove StatusBarPanels dynamically from a StatusBar,
depending on user input.

The problem is that when I use the StatusBar.Remove(panel) method the
'Parent' propery of the StatusBarPanel isn't cleared, it still says that
it's parent is the StatusBar, so when I later try to add this panel
again I get an exception telling me that the panel already has a parent.

StatusBar.Panels.Clear() correctly clears the Parent-prop, but I don't
want to remove all the panels...

How simple this would be I there only was a 'Visible' property on a
StatusBarPanel. :)

I tried searching the groups and only found this in one place, with no
reply :/

http://shorl.com/hedosuvafihy
or
http://groups.google.com/groups?hl=...1c2a606$4b0c3120$8af82ecf@TK2MSFTNGXA03#link1

Thanks,
Glenn
 
R

Rhett Gong

Hi Glenn,
When using spy++, we can see that the panel is not a child window. We
know StatusBarPanel is derived from System.ComponentModel.Component. It is
added as a setting of StatusBar.So if you remove this panel, you can't use
it in another status bar.
StatusBarPanel's parent property is set to the container when you add
it to a statusbar. From the decompiled code, we can see these lines:
//------------------------------------------------
// in public virtual void Insert(int index, StatusBarPanel value)

if (value.parent != null)
{
throw new ArgumentException(SR.GetString("ObjectHasParent"), "value");
}
// ......................
value.parent = this.owner;
//-----------------------------------------------
I think it is a limitation for StatusBarPanel.
For the workaround, I suggest you copying the panel's property to
another place when removing it, create a new panel, assign the property to
this new panel, and add it to another Statusbar.




Rhett Gong [MS]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top