简体   繁体   English

单击C#中的按钮将面板置于最前面

[英]Bringing panel to front on a click of a button in c#

I would like some help with code so my panels get brought to front when I click a button. 我需要一些代码方面的帮助,以便在单击按钮时将面板显示在最前面。

I have tried 我努力了

private void button22_Click(object sender, EventArgs e)
{
    panel4.BringToFront();
}

but that didn't seem to work for me. 但这似乎对我不起作用。 Does anyone know what I'm doing wrong or how I could get this working? 有谁知道我在做什么错或如何使它正常工作? I am in c# winforms. 我在使用c#winforms。

That should work fine. 那应该工作正常。 You code says panel4 so I assume you have multiple panels. 您的代码说的是panel4所以我假设您有多个面板。

If you have placed panel3 on panel4 , then BringToFront() will bring both forward and may look like there is no change. 如果你已经放置panel3panel4 ,然后BringToFront()将向前既带来和可能看起来像没有变化。 Make sure both panels have the form as their parent. 确保两个面板的父窗体都为表单。 You can do this by cut and paste, or making sure that you click the form canvas (not an existing panel) when you add the other panels. 您可以通过剪切和粘贴来执行此操作,或者确保在添加其他面板时单击表单画布(不是现有面板)。

The same for buttons, textboxes etc, if you draw them on to a panel, they will stay as is on that panel when you bring them forwards. 按钮,文本框等的用法相同,如果将它们绘制到面板上,则当它们向前移动时,它们将保留在该面板上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM