重新排列panel中的按钮,如图
排列前:


排列后:

代码:
        void ArrangeButtons(Panel pn)
         {
            int x = 0, y = 0;
             System.Windows.Forms.Control.ControlCollection ct = pn.Controls;

            //for (int i = 0; i < ct.Count; i++)
            for (int i = ct.Count - 1; i >= 0; i--)
             {
                 ct[i].Location = new System.Drawing.Point(x, y);
                 x = x + ct[i].Width + 5;
                if (x + ct[i].Width > pn.Width)
                 {
                     x = 0;
                     y = y + ct[i].Height + 5;
                 }
             }
         }

        private void buttonArrangeButtons_Click(object sender, EventArgs e)
         {
             ArrangeButtons(panel1);
         }

posted on 2010-08-13 15:28  努力实现目标  阅读(1957)  评论(0编辑  收藏  举报