开发者

Using a delegate to trigger an event if a panel is visible?

I am trying 开发者_Python百科to see a reason to use a delegate, and from what I know, a delegate basically what's for an event.

The event I would have would be in Windows Forms. I have a panel that starts not visible, but when it becomes visible everything in the background becomes disabled (a popup).

I could have it so that whatever makes the panel visible will also cause everything to become disabled, as I usually do. But could I set up a delegate or an event, so whenever that panel is visible, it calls a method that disables everything?

I just can't figure how to work that out with a delegate.


How about:

panel.VisibleChanged += (sender, args) =>
{
    if (panel.Visible) // Just become visible
    {
        // Disable everything else
    }
};


System.Windows.Forms.Controls (including Panels) have a VisibleChanged event you can bind to. So

myPanel.VisibleChanged += OnMyPanelVisibleChanged;

Or inline:

myPanel.VisibleChanged += (sender, e) => this.Enabled = myPanel.Visible;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜