触发on.Scroll()时移动面板

时间:2014-06-20 09:40:30

标签: c# winforms panel

我有一个面板MainPanel,其中包含2个面板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);

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,我编辑了上面的代码来展示。我用2个séparâtespnIntersectRoles和pnIntersectOperations以及2个文本框,tb和tbCopy完成了它。对于我的问题,我只需要在拖动时也这样做。并更新文本框文本和位置。是的,我现在很高兴