TableLayoutPanel行和列移动 [英] TableLayoutPanel rows and column move

查看:100
本文介绍了TableLayoutPanel行和列移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表格布局面板中,如果我拖动某些特定行,则整个面板都在移动.我只想只移动选定的行或列.我该怎么办?

使用此代码移动整个tablelayoutpanel:

In table layout panel, if i drag some particular row,gthe entire panel is moving. I just want to move only the selected row or column. How can i do this?

Using this code to move entire tablelayoutpanel:

private void tableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
    {
      int GRow = 0;
      int GColumn = 0;

        try
        {
            if (resizing)
            {

                columnStyles[GColumn].SizeType = SizeType.Absolute;
                rowStyles[GRow].SizeType = SizeType.Absolute;
                rowStyles[GRow].Height += e.Y - rowStyles[GRow].Height;
                columnStyles[GColumn].Width += e.X - columnStyles[GColumn].Width;

            }
        }
        catch (Exception ex)
        {
           // MessageBox.Show(ex.ToString());
        }
    }



要获得GRow和GColumn,请使用以下代码:



To get the GRow and GColumn used this below code:

private void tableLayoutPanel1_MouseClick(object sender, MouseEventArgs e)
       {
           try
           {
               int Row = 0;

               int VSpace = 0;
               GRow = Row;
               foreach (int h in tableLayoutPanel1.GetRowHeights())
               {
                   int Column = 0;
                   int HSpace = 0;

                   foreach (int w in tableLayoutPanel1.GetColumnWidths())
                   {
                       Rectangle Rect = new Rectangle(HSpace, VSpace, w, h);
                       if ((Rect.Contains(e.Location)))
                       {
                           GColumn = Column;
                           MessageBox.Show("Row Value = " + Row.ToString() + " " + "Column Value = " + Column.ToString(), "TableLayoutPanel", MessageBoxButtons.OK, MessageBoxIcon.Information);
                           return;
                       }
                       HSpace += w;
                       Column += 1;
                   }
                   VSpace += h;
                   Row += 1;
               }

           }

           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString ());
           }
       }



我只想移动特定的行或列.帮帮我.



I want to move only the specific row or column. Help me.

推荐答案

如果我理解正确,则想在两列之间移动边框.因此,从该边框的角度来看,您有左右两列.

我会尝试这样的操作:
If I understand correctly, You want to move the border between two columns. So from that border''s point of view, you have a left and a right column.

I''d try something like this:
private System.Windows.Forms.TableLayoutPanelColumnStyle _leftColumnStyle = null;
private System.Windows.Forms.TableLayoutPanelColumnStyle _rightColumnStyle = null;
private System.Drawing.Point _locationWhereUserStartedDragging = new Point(-1, -1);

tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
{
    _locationWhereUserStartedDragging = e.Location;

    GetColumnsThatUserClickedInBetween(e, ref _leftColumnStyle, ref _rightColumnStyle);

    foreach(ColumnStyle style in tableLayoutPanel1.ColumnStyles)
    {
        if( style.Equals(_rightColumnStyle))
        {
            style.SizeType = SizeTypes.AutoSize;
        }
        else
        {
            style.SizeType = SizeTypes.Absolute;
        }
    }
}

tableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
{
    _leftColumnStyle.Width = e.Location.X - _locationWhereUserStartedDragging.X;
}

当用户按下鼠标按钮时,我们的应用程序会记住该位置以计算用户可能将鼠标移动了多远.
它还会记住设置为具有自动计算宽度的单列.因此,当我们更改左列的宽度时,应紧跟右列.

When the user presses the mouse button down, our application remembers where that was to calculate how far the user may have moved the mouse.
It also remembers the single column that is set to have an automatically calculated width. So when we change the left column''s width, the right one should follow.


这篇关于TableLayoutPanel行和列移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆