Friday, 18 July 2008

VisibleChanged Event, missing in the Compact Framework

If you need to do something in the VisibleChanged event of a form or control, using the Compact Framework, you´ll see that this event is missing.

You can easily fix this shadowing the Visible property with a newer one, and firing the event by yourself. Just like this:

public event System.EventHandler VisibleChanged;
public new bool Visible
get { return base.Visible; }
if (base.Visible != value)
base.Visible = value;
if (VisibleChanged != null)
VisibleChanged(this, EventArgs.Empty);


crisco said...

Great example! Thanks for the post.

Bryan said...

In CompactFramework v2.0 and v3.5, the method Form.ShowDialog() sets base.Visible. Unfortunately, this workaround fails for modal dialogs.