日期:2014-05-18  浏览次数:20886 次

TableLayoutPanel 这个控件有没有替代的,而且可以动态Sizable
TableLayoutPanel 
可以通过程序动态调节大小,添加,减少rows
但是似乎无法有一个sizable的border,让用户动态调整
请问有没有类似控件可以代替?
非常感谢?
希望可以捡拾牙慧!

请各位大大帮忙!!谢谢!


------解决方案--------------------
自己画出来,然后在鼠标事件中做处理,别总想着找现成的,程序员不是摆控件的工具
------解决方案--------------------
C# code

   /// <summary>
        /// 调整画面布局
        /// </summary>
        /// <param name="videoNum"></param>
        /// <returns></returns>
        private bool InitializeVideo(int videoNum)
        {
            //计算行列
            int rowcol;
            if (videoNum <= 0 || !int.TryParse(Math.Sqrt(videoNum).ToString(), out rowcol))
            {
                return false;
            }
            //计算宽高
            int WidthHeight = (int)(MainPanel.Width / rowcol);
           
            //重新设置表格
            //MainPanel为TableLayoutPanel控件
            MainPanel.Controls.Clear();
            MainPanel.RowCount = MainPanel.ColumnCount = rowcol;
            MainPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
            MainPanel.Refresh();
            for (int i = 0; i < MainPanel.ColumnStyles.Count; i++)
            {
                MainPanel.ColumnStyles[i].SizeType = SizeType.Absolute;
                MainPanel.ColumnStyles[i].Width = WidthHeight;
            }
            for (int i = 0; i < MainPanel.RowStyles.Count; i++)
            {
                MainPanel.RowStyles[i].SizeType = SizeType.Absolute;
                MainPanel.RowStyles[i].Height = WidthHeight;
            }

            //添加控件
            for (int i = 0; i < videoNum; i++)
            {
                PictureBox pVideo = new PictureBox();
                pVideo.Padding = pVideo.Margin = new Padding(0);
                pVideo.Name = "pVideo" + i.ToString();
                pVideo.Width = pVideo.Height = WidthHeight;
                pVideo.Dock = DockStyle.Fill;
                pVideo.BackgroundImage = Resources.bg;
                pVideo.BackgroundImageLayout = ImageLayout.Stretch;
                pVideo.Click += new EventHandler(pVideo_Click);

                MainPanel.Controls.Add(pVideo, i % rowcol, i / rowcol);
            }


            return true;
        }

        /// <summary>
        /// 点击图像事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pVideo_Click(object sender, EventArgs e)
        {
            PictureBox pVideo = (PictureBox)sender;
            //MessageBox.Show(pVideo.Name);
            if (MainPanel.GetColumnSpan(pVideo) == 1)
            {
                //隐藏其它控件
                foreach (Control ctr in MainPanel.Controls)
                {
                    if (ctr.Name != pVideo.Name)
                        ctr.Visible = false;
                }
                pos = MainPanel.GetPositionFromControl(pVideo);
                MainPanel.SetCellPosition(pVideo, new TableLayoutPanelCellPosition(0, 0));
                MainPanel.SetRowSpan(pVideo, MainPanel.RowCount);
                MainPanel.SetColumnSpan(pVideo, MainPanel.ColumnCount);
            }
            else
            {
                //显示所有控件
                foreach (Control ctr in MainPanel.Controls)
                {
                    ctr.Visible = true;
                }
                MainPanel.SetCellPosition(pVideo, pos);
                MainPanel.SetRowSpan(pVideo, 1);
                MainPanel.SetColumnSpan(pVideo, 1);
            }
        }