Intercepting the value change of SetChildIndex

妖精的绣舞 提交于 2019-12-25 02:24:54

问题


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


回答1:


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;
        }


来源:https://stackoverflow.com/questions/4007663/intercepting-the-value-change-of-setchildindex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!