拦截SetChildIndex的值变化

发布于 2024-09-28 23:01:59 字数 144 浏览 0 评论 0原文

在 .NET CF 形式中,我有多个面板。我想要一个属性,应该始终通知面板是否位于前面。

可以使用 GetChildIndex() 方法来完成此操作吗?

如果是,我如何拦截对 SetChildIndex() 的更改?

提前致谢

In a .NET CF-form i have multiple panels. I want to have a property that should always be informed about if a panel is in the front.

Can this be done using the GetChildIndex() method?

If yes, how do i intercept the change to SetChildIndex()?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏林苍穹下 2024-10-05 23:01:59

对于对未来使用感兴趣的每个人:

只需为每个面板的 Paint 事件添加一个新的事件处理程序,例如:

panel1.Paint += new PaintEventHandler(panel1_Paint);
panel2.Paint += new PaintEventHandler(panel2_Paint);

在每个事件处理程序中只需调用一个方法来检索所有面板的状态,如下所示:

void panel2_Paint(object sender, PaintEventArgs e)
        {
            GetPanelStates();

        }

        void panel1_Paint(object sender, PaintEventArgs e)
        {
            GetPanelStates();
        }



        void GetPanelStates()
        {
            Panel2IsInFront = panel2.Parent.Controls.GetChildIndex(panel2) == 0;
            Panel1IsInFront = panel1.Parent.Controls.GetChildIndex(panel1) == 0;
        }

For everybody who is interested for future use:

simply add a new event handler for the Paint event of each panel, for example:

panel1.Paint += new PaintEventHandler(panel1_Paint);
panel2.Paint += new PaintEventHandler(panel2_Paint);

and in each of the event handlers just call a Method which retrieves the state of all the panels like so:

void panel2_Paint(object sender, PaintEventArgs e)
        {
            GetPanelStates();

        }

        void panel1_Paint(object sender, PaintEventArgs e)
        {
            GetPanelStates();
        }



        void GetPanelStates()
        {
            Panel2IsInFront = panel2.Parent.Controls.GetChildIndex(panel2) == 0;
            Panel1IsInFront = panel1.Parent.Controls.GetChildIndex(panel1) == 0;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文