重新定位控件时移动表单的内容

发布于 2024-11-07 11:25:08 字数 1330 浏览 3 评论 0原文

假设我的表单上有许多 控件,当用户单击其中一个控件时,其高度将会扩展。这意味着,当前,当此单击的控件展开时,其下方的其他控件将与展开的控件重叠。

但我想要发生的是,使扩展控件下方的每个控件向下滑动,以便它们再次位于扩展控件下方。

我知道如何处理滑动,但我只是不知道如何制作每个控件,除了每次移动给定控件时移动一个控件。

非常感谢任何帮助,谢谢!

这就是我的想法:

void newOrderReceived(object sender, EventArgs e)
{
    foreach(Control OrderNotificationBox in OrdersPanel.Controls)
    {
        if(OrderNotificationBox is NotificationBox) // Checks to see if the control is a NotificationBox
        {
            // Add my code to slide controls down.
        }
    }
}

但是...我如何知道该控件是否位于扩展控件的下方

这是我应该如何更改扩展控件下方所有控件的位置吗?

编辑:只是有一个想法,要检查通知框是否位于扩展通知框下方,请参阅下面修改后的代码:

void newOrderReceived(object sender, EventArgs e)
{
    foreach(Control OrderNotificationBox in OrdersPanel.Controls)
    {
        if(OrderNotificationBox is NotificationBox) // Checks to see if the control is a NotificationBox
        {
            if(OrderNotificationBox.Location.Y <= ExpandedNotificationBox.Location.Y + ExpandedNotificationBox.Size.Width)
            {
                // Add my code to slide controls down.
            }
        }
    }
}

但这足够吗?目前,这是有效的,所以我想我只是回答了我自己的问题。但是,没有更好的方法吗?更优雅/更有效的方式?

下面是它的外观示例: 通过正确重新定位控件来扩展控制

Let's just say that I have many controls on my Form, and when a User clicks on one of them, its height will expand. This means that, currently, when this clicked-control expands, other controls below it will become overlapped by the expanded control.

But what I want to happen, is for each Control below the expanded control to slide down, so that they are below the expanded control again.

I know how to handle sliding, but I just don't know how to make every control except for one move everytime a given control is moved.

Any help at all is greatly appreciated, thank you!

This is what I was thinking:

void newOrderReceived(object sender, EventArgs e)
{
    foreach(Control OrderNotificationBox in OrdersPanel.Controls)
    {
        if(OrderNotificationBox is NotificationBox) // Checks to see if the control is a NotificationBox
        {
            // Add my code to slide controls down.
        }
    }
}

But... How do I know if the control is below the expanded control?

Is this how I should go about changing the location of all controls below the expanded control?

Edit: Just had a thought, to check to see if a NotificationBox is below the Expanded NotificationBox, see revised code below:

void newOrderReceived(object sender, EventArgs e)
{
    foreach(Control OrderNotificationBox in OrdersPanel.Controls)
    {
        if(OrderNotificationBox is NotificationBox) // Checks to see if the control is a NotificationBox
        {
            if(OrderNotificationBox.Location.Y <= ExpandedNotificationBox.Location.Y + ExpandedNotificationBox.Size.Width)
            {
                // Add my code to slide controls down.
            }
        }
    }
}

But would this be sufficient? Currently, this is working, so I guess I just answered my own question. But, isn't there a better way to do this? A more elegant/efficient way?

Here's a sample of how it should look:
Expanded Control with properly re-located controls

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

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

发布评论

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

评论(3

夜血缘 2024-11-14 11:25:08

FlowLayoutPanel 为您提供动态布局,您可以在其中可以调整其中任何控件的大小,并且下面的所有控件都会自动滑动。有许多策略可以使用流程布局面板的组/列来实现整个表单所需的外观。一些谷歌搜索会揭示其中的一些内容。

在此处输入图像描述

例如,在上面的表单中,调整 Button1 控件的大小只会使下面的所有控件进一步向下流动形式。您也可以在设计时尝试这样做。将表单拖放到流程布局面板中,将 3-4 个控件放入容器中并开始试验。

FlowLayoutPanel provides you with dynamic layout where you can resize any control in it and all below controls will slide automatically. There are many strategies to using groups/columns of flow layout panels to be able to achieve the desired look for the whole form. Some googling will reveal some of these.

enter image description here

For instance in the form above, resizing the button1 control simply flows all the below controls to further down on the form. You can try that at the design time also. Drop the form a flow layout panel, drop 3-4 control in the container and start experimenting..

筱武穆 2024-11-14 11:25:08

对于每个可扩展内容,请使用面板。
将面板一个接一个地停靠在另一个面板下(使用 panel1.Dock = DockStyle.Top。对于最底部的面板,使用 panel1.Dock = DockStyle.Fill)。
将子控件放置在每个可扩展面板内,并相应地设置内部控件的 Anchor 属性。
当您展开一个面板时,其余面板将自动调整。您不需要为此编写代码。您只能更改当前展开的面板的高度

For each expandable content use Panel.
Dock your panels one under another (Use panel1.Dock = DockStyle.Top. For the very bottom panel use panel1.Dock = DockStyle.Fill).
Place your child controls inside of each expandable panel, set inner controls' Anchor properties accordingly.
When you expand one panel, the rest of the panels will adjust automatically. You don't need to code for this. You will only change Height of a panel that you currently expand.

雨夜星沙 2024-11-14 11:25:08

您需要的是某种“ExplorerBar”功能。有几个控件库提供了这种功能,我在 CodeProject 上这里找到了这篇文章 那是免费的。

What you need is some kind of 'ExplorerBar' functionality. There are several control libraries that offer that, and I found the article here on the CodeProject that has it for free.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文