Question

I have program with two tabs in a TabController, I also have a panel I want to always have in front. Despite what tabpage I am in. I tried setting the panel to BringToFront(), but that don´t seem to work when I change tabpage. Any suggestions how to solve this?

Was it helpful?

Solution

If the Panel is contained by the TabPage, then you'd have to manually switch it to the current tab whenever the tab changes, then call BringToFront().

An alternative would be to make the Panel so it's directly contained by the Form, but in front of the TabControl (like it's "floating" over it). Then it would just stay there. You'd have to either manually fiddle with the Panel's Location() property to get it right (you couldn't drag it over the TabPage as then it would drop into it), or you could position it properly via code in the Load() event of the Form.

Edit:

For instance, if you properly positioned "panel1" in the TabPage at design-time, you could switch it to the Form using code like this:

    private void Form1_Load(object sender, EventArgs e)
    {
        Point pt = panel1.PointToScreen(new Point(0, 0));
        panel1.Parent = this;
        panel1.Location = this.PointToClient(pt);
        panel1.BringToFront();
    }

OTHER TIPS

Set the panel outside the tabcontroller and set it's dockstyle. Also set the dockstyle of the tabcontroller.

Panel belongs to a specific tabpage. When you change to another tabpage and call BringToFront(), it doesn't make anything, because you're on another tabpage right now. So you need to workaround that with righting some code. There are two ways:

1) You can place that panel on every tabpage in design time (if you don't need some shared data on that panel).

2) You should hook OnTabPageChanged event and move panel from old tabpage to the page you switched to (if you do need some shared data on that panel). I think this is your case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top