【问题标题】:Move Panel when pn.Scroll() is fired触发 on.Scroll() 时移动面板
【发布时间】:2014-06-20 09:40:30
【问题描述】:

我有一个面板MainPanel,其中包含两个面板pnContRoles(水平滚动)和pnContOperations(垂直滚动)。每个都有不同的大小和位置。我有另一个面板pnIntersection,我默认输入pnContOperations。我想将pnIntersectionpnContOperations 更改为pnContRoles。这必须伴随pnIntersection 的大小和位置的变化。所有这些都是为了能够在滚动pnContRolespnContOperations 时相应地移动pnIntersection。在每个面板中,控件都是文本框(如果重要的话)。

TextBox tb = new TextBox();
        TextBox tbCopy = new TextBox();
        ToolTip TTL = new ToolTip();
        String TooltipL;

        tb.BorderStyle = BorderStyle.Fixed3D;
        tb.Name = idRoleL + idOperationL.ToString();
        tb.Text = valeurL;
        tb.TextAlign = HorizontalAlignment.Right;
        tb.ScrollBars = ScrollBars.None; //pour enlever les scrollbars dans tout les textboxes
        tb.HideSelection = true;//pour ne pas avoir le focus dans le precedent textbox
        tb.Size = new Size(100, 20);
        tb.Location = new Point((posRoleL - 1) * 140 + 20 + 2, (posOperationL - 1) * 40 + 10 + 2);
        tb.Visible = true;
        tb.Cursor = Cursors.IBeam;
        tb.WordWrap = false;

        tbCopy.BorderStyle = BorderStyle.Fixed3D;
        tbCopy.Name = tb.Name;
        tbCopy.Text = tb.Text;
        tbCopy.TextAlign = HorizontalAlignment.Right;
        tbCopy.ScrollBars = ScrollBars.None; //pour enlever les scrollbars dans tout les textboxes
        tbCopy.HideSelection = true;//pour ne pas avoir le focus dans le precedent textbox
        tbCopy.Size = new Size(100, 20);
        tbCopy.Location = tb.Location;
        tbCopy.Visible = true;
        tbCopy.Cursor = Cursors.IBeam;
        tbCopy.WordWrap = false;

        TooltipL = "Veuillez écrire des numéros decimals positifs, merci.";            
        TTL.SetToolTip(tb, TooltipL);

        #endregion

        #region EVENEMENTS TEXTBOX
        //Evenement quand le text change(si le texte quand écrit ce sont des numéros positif)            
        tb.Leave += (senderL, eL) =>
        {
            string patron = @"^[0-9]*\.?[0-9]*$";
            string input = tb.Text;
            Match m = Regex.Match(input, patron);

            if (m.Success)
            {
                EventControlAddin(5, (string)idOperationL.ToString().PadRight(10) + ";" + idRoleL.PadRight(10) + ";" + (string)tb.Text);
            }
            else
            {
                MessageBox.Show("Vous devez écrire un numéro valide et decimal positif, s'il vous plaît.");
                tb.Text = "???";
                tb.BackColor = Color.IndianRed;
                tb.Focus();
            }

        };

        #endregion            

        pnContRoles.Scroll += (senderL, eL) =>
        {                
            pnContRoles.BringToFront();               
        };
        pnContOperations.Scroll += (senderL, eL) =>
        {   
            pnContOperations.BringToFront();
        };            

        #region AJOUTS

        pnIntersectRoles.Location = new Point(0, 40);
        pnIntersectRoles.Size = new Size(nRolesG * 140, 320);
        pnIntersectRoles.Parent = pnContRoles;

        pnIntersectRoles.Controls.Add(tbCopy);
        pnContRoles.Controls.Add(pnIntersectRoles);
        MainPanel.Controls.Add(pnContRoles); 

        pnIntersectOperations.Location = new Point(220, 0);
        pnIntersectOperations.Size = new Size(840, (nOperationsG + nPhasesG) * 40);
        pnIntersectOperations.Parent = pnContOperations;

        pnIntersectOperations.Controls.Add(tb);
        pnContOperations.Controls.Add(pnIntersectOperations);
        MainPanel.Controls.Add(pnContOperations);

【问题讨论】:

  • 先删除,再添加到其他面板。它不能有两个父母。
  • 我编辑了我的问题。 @DonBoitnott,谢谢,我从 pnContOperations 中删除并将其添加到 pnContRoles 但它不起作用。位置和大小都不好。如果我更改 pnIntersection 的大小和位置,它就会消失。也许我也必须删除其中的文本框,然后添加所有内容...
  • 需要搬家吗?两个相同的设置,并根据需要隐藏/显示它们呢?重新育儿控制充其量是笨拙的。
  • 我将在大小、位置和父级上做两个 pnIntersection différents。我将从一个中删除文本框并根据需要添加到另一个中。稍后我会发布可能的解决方案...这可行吗?
  • 目前不工作。我编辑了代码。在 pnIntersectRoles 和 pnIntersectOperations 中生成的文本框是相同的。也许我也需要重复?

标签: c# winforms panel


【解决方案1】:

我找到了解决方案,我编辑了上面的代码以显示。我用 2 个单独的 pnIntersectRoles 和 pnIntersectOperations 以及 2 个文本框 tb 和 tbCopy 来完成它。对于我的问题,我只需要在拖动时做同样的事情。并更新文本框文本和位置。是的,我现在很开心

【讨论】:

    猜你喜欢
    • 2013-05-19
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 2013-07-30
    • 2013-01-05
    相关资源
    最近更新 更多