在C#中更改标签页时,如何将面板设置为始终位于顶部? [英] How can I set a panel to be always on top when changing tabpages in C#?

查看:112
本文介绍了在C#中更改标签页时,如何将面板设置为始终位于顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TabController中有带有两个选项卡的程序,也有一个我想一直放在前面的面板.尽管我使用的是标签页.我尝试将面板设置为BringToFront(),但是当我更改标签页时,这似乎不起作用.有什么建议可以解决这个问题吗?

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?

推荐答案

如果小组是的包含按所述的TabPage,那么你将不得不手动将其切换到当前标签每当标签的变化,然后调用BringToFront().

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().

一种替代方法是将Panel制作为直接包含在 Form 中,但位于TabControl的前面(就像它浮动"在其上方一样).然后它会呆在那里.您必须手动调整Panel的Location()属性以使其正确(您不能将其拖到TabPage上,否则它会掉进去),或者可以通过Load()中的代码正确定位它)事件.

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.

例如,如果在设计时将"panel1"正确放置在 TabPage 中,则可以使用以下代码将其切换为表单":

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

这篇关于在C#中更改标签页时,如何将面板设置为始终位于顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆