太多的ControlCollection

时间:2019-03-17 21:12:48

标签: user-controls location controlcollection

我的自定义控件的子控件过多。问题是这些子控件必须排列整齐。

///
    class GroupControl : UserControl
    {
         ///
        /// 
        #region CONSTRUCTION
        internal GroupControl(ListViewGroup lvgroup)
        {
            ///
            Title = lvgroup.Header;
        }
        #endregion

        /// <summary>
        /// 
        #region EVENT METHODS
        private void GroupControl_SizeChanged(object sender, EventArgs e)
        {
            ///
            IEnumerator enumer = Controls.GetEnumerator();

            ///
            int top = 0;

            ///
            while (enumer.MoveNext())
            {
                ///
                Label item = null;

                ///
                try { item = enumer.Current as Label; } catch { }

                ///
                if (item == null)
                    continue;

                ///
                item.Size = new Size(Width, 21);
                item.Location = new Point(0, top);

                ///
                top += item.Height;
            }

            ///
            enumer = null;
        }

        #endregion


    }

现在问题是item.Location = new Point(0, top);,当top大于int.MaxValue为32767时,之后的所有项目都具有相同的Top值。

有人知道有关此问题的任何解决方法吗?谢谢

0 个答案:

没有答案