C# WinForms SplitContainer 面板工具栏

发布于 2025-01-16 20:28:35 字数 370 浏览 3 评论 0原文

WinForms .NET 6.03 (C#)

在一个具有传统菜单和工具栏停靠在顶部的窗体中...

我在左侧面板中有一个拆分容器(垂直拆分器)我有一个停靠在顶部的工具栏和一个用户控件填充Panel1 位于面板工具栏下方。

当我调整面板大小时,工具栏消失,用户控件在面板中向上移动。

这在 .NET 4.6 中不是问题。我现在才在 .NET 6.03 中构建时才看到它

有修复吗?

输入图片此处描述

WinForms .NET 6.03 (C#)

In a Form that has a traditional menu and toolbar docked across the top...

I have a split container (vertical splitter) in the left panel I have a toolbar docked to the top and a user control filling Panel1 below the panel's toolbar.

When I resize the panel, the toolbar disappears and the user control shifts up in the panel.

This was not a problem in .NET 4.6. I'm only seeing it now that I'm building in .NET 6.03

Is there a fix?

enter image description here

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

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

发布评论

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

评论(2

孤凫 2025-01-23 20:28:35

事实证明,这是一个 z 顺序问题。不知何故,在执行过程中,工具条失去了有关对接的最高条件。

It turned out that this was a z-order problem. Somehow during execution, the toolstrip was losing it's topmost condition regarding docking.

娇妻 2025-01-23 20:28:35

请像这样尝试:

不要忘记右键单击项目并选择同步命名空间以根据您的项目更新命名空间。

namespace DiscountCard.View.CustomControl
{
public partial class CtechSplitContainer : SplitContainer
{
private ToolStripContainer toolStripContainer1;
private ToolStrip toolStrip1;
private ToolStripButton button1;

private ToolStripContainer toolStripContainer2;
private ToolStrip toolStrip2;
private ToolStripButton button2;

public CtechSplitContainer()
{
InitializeComponent();

toolStripContainer1 = new ToolStripContainer();
toolStrip1 = new ToolStrip();
button1 = new ToolStripButton();

button1.Text = "

Try like this:

Don't forget to right-click on the Project and select Sync Namespace to update the namespace according to your project.

namespace DiscountCard.View.CustomControl
{
    public partial class CtechSplitContainer : SplitContainer
    {
        private ToolStripContainer toolStripContainer1;
        private ToolStrip toolStrip1;
        private ToolStripButton button1;

        private ToolStripContainer toolStripContainer2;
        private ToolStrip toolStrip2;
        private ToolStripButton button2;

        public CtechSplitContainer()
        {
            InitializeComponent();

            toolStripContainer1 = new ToolStripContainer();
            toolStrip1 = new ToolStrip();
            button1 = new ToolStripButton();

            button1.Text = "????";
            button1.Click += Button1_Click;
            button1.DoubleClick += Button1_DoubleClick;

            // Add items to the ToolStrip.
            ToolStripItem[] toolStripItem1 = new ToolStripItem[] { button1 };
            toolStrip1.Items.AddRange(toolStripItem1);
            toolStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
            toolStrip1.BackColor = Color.White;
            toolStrip1.Dock = DockStyle.Top;

            // Add the ToolStrip to the top panel of the ToolStripContainer.
            toolStripContainer1.TopToolStripPanel.Controls.Add(toolStrip1);
            toolStripContainer1.Dock = DockStyle.Right;
            toolStripContainer1.Height = button1.Width;
            toolStripContainer1.Width = button1.Width;

            // Add the ToolStripContainer to the Panel1.
            this.Panel1.Controls.Add(toolStripContainer1);
            this.Panel1.BackColor = Color.White;


            toolStripContainer2 = new ToolStripContainer();
            toolStrip2 = new ToolStrip();
            button2 = new ToolStripButton();

            button2.Text = "????";
            button2.Click += Button2_Click;
            button2.DoubleClick += Button2_DoubleClick;

            // Add items to the ToolStrip.
            ToolStripItem[] toolStripItem2 = new ToolStripItem[] { button2 };
            toolStrip2.Items.AddRange(toolStripItem2);
            toolStrip2.LayoutStyle = ToolStripLayoutStyle.Table;
            toolStrip2.Dock = DockStyle.Top;

            // Add the ToolStrip to the top panel of the ToolStripContainer.
            toolStripContainer2.TopToolStripPanel.Controls.Add(toolStrip2);
            toolStripContainer2.Dock = DockStyle.Right;
            toolStripContainer2.Height = button2.Width;
            toolStripContainer2.Width = button2.Width;
            toolStrip2.BackColor = Color.White;

            // Add the ToolStripContainer to the Panel2.
            this.Panel2.Controls.Add(toolStripContainer2);
            this.Panel2.BackColor = Color.White;

            this.SplitterWidth = 1;

            if (this.Orientation == Orientation.Vertical)
            {
                this.SplitterDistance = this.ClientSize.Width / 2;
            }
            else
            {
                this.SplitterDistance = this.ClientSize.Height / 2;
            }

            this.BackColor = Color.White;
        }

        private void Button1_Click(object? sender, EventArgs e)
        {
            if (button1.Text == "????")
            {
                button1.Text = "????";
                this.Panel1Collapsed = false;
                this.Panel2Collapsed = true;
            }
            else
            {
                button1.Text = "????";
                this.Panel1Collapsed = false;
                this.Panel2Collapsed = false;
            }
        }
        private void Button1_DoubleClick(object? sender, EventArgs e)
        {
            button1.PerformClick();
        }

        private void Button2_Click(object? sender, EventArgs e)
        {
            if (button2.Text == "????")
            {
                button2.Text = "????";
                this.Panel1Collapsed = true;
                this.Panel2Collapsed = false;
            }
            else
            {
                button2.Text = "????";
                this.Panel1Collapsed = false;
                this.Panel2Collapsed = false;
            }
        }
        private void Button2_DoubleClick(object? sender, EventArgs e)
        {
            button2.PerformClick();
        }

    }
}

Result

1. Normal

enter image description here

2. Maximized

enter image description here

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