码迷,mamicode.com
首页 > Windows程序 > 详细

C#中,重新排列panel中的按钮

时间:2018-10-19 02:26:28      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:i++   nta   obj   end   poi   draw   https   排列   vat   

https://www.cnblogs.com/hfzsjz/archive/2010/08/13/1799068.html

   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);
         }
   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);
         }

 

C#中,重新排列panel中的按钮

标签:i++   nta   obj   end   poi   draw   https   排列   vat   

原文地址:https://www.cnblogs.com/wangchuang/p/9813903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!