Esempio n. 1
0
        /// <summary>
        /// 初始化指定数量的照片控件
        /// </summary>
        /// <param name="count"></param>
        public void InitPictureBox(int count)
        {
            int c = 0;

            pics = new  List <UserPhotoItem2> ();
            int rowMax = rows == 0?99999:rows;
            //调整位置
            int adjustX = 0, adjustY = 0;

            if (itemAlign == ContentAlignment.MiddleCenter || itemAlign == ContentAlignment.MiddleLeft || itemAlign == ContentAlignment.MiddleRight)
            {
                int rowCount = (int)Math.Ceiling(count * 1.0 / columns);
                var needY    = rowCount * (pictureSize.Height + 2 * pictureBorderWidth) + (rowCount - 1) * cellHeight;
                adjustY = (this.Height - needY) / 2;
            }
            if (itemAlign == ContentAlignment.BottomCenter || itemAlign == ContentAlignment.MiddleCenter || itemAlign == ContentAlignment.TopCenter)
            {
                var needX = columns * (pictureSize.Width + 2 * pictureBorderWidth) + (columns - 1) * cellWidth;
                adjustX = (this.Width - needX) / 2;
            }
            if (itemAlign == ContentAlignment.BottomRight || itemAlign == ContentAlignment.MiddleRight || itemAlign == ContentAlignment.TopRight)
            {
                var needX = columns * (pictureSize.Width + 2 * pictureBorderWidth) + (columns - 1) * cellWidth;
                adjustX = this.Width - needX;
            }
            //初始化照片控件
            for (int row = 0; row < rowMax; row++)
            {
                for (int column = 0; column < Columns; column++)
                {
                    if (count == c)
                    {
                        return;
                    }
                    UserPhotoItem2 p = new UserPhotoItem2();
                    p.ShowLabel = showLabel;
                    p.Size      = pictureSize;

                    int width  = pictureSize.Width + cellWidth;
                    int height = pictureSize.Height + cellHeight;
                    p.Location = new Point(column * width + pictureBorderWidth + adjustX, row * height + pictureBorderWidth + adjustY);
                    this.Controls.Add(p);
                    pics.Add(p);
                    c++;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 初始化指定数量的照片控件
        /// </summary>
        /// <param name="count"></param>
        public void InitPictureBox(int count)
        {
            int c = 0;
           pics = new  List<UserPhotoItem2> ();
           int rowMax = rows==0?99999:rows;
            //调整位置
           int adjustX = 0, adjustY = 0;
           if (itemAlign == ContentAlignment.MiddleCenter || itemAlign == ContentAlignment.MiddleLeft || itemAlign == ContentAlignment.MiddleRight)
           {
               int rowCount = (int)Math.Ceiling(count*1.0 / columns);
               var needY = rowCount * (pictureSize.Height + 2 * pictureBorderWidth) + (rowCount - 1) * cellHeight;
               adjustY = (this.Height - needY) / 2;
           }
           if (itemAlign == ContentAlignment.BottomCenter || itemAlign == ContentAlignment.MiddleCenter || itemAlign == ContentAlignment.TopCenter)
           {
               var needX = columns * (pictureSize.Width + 2 * pictureBorderWidth) + (columns - 1) * cellWidth;
               adjustX = (this.Width - needX) / 2;
           }
           if (itemAlign == ContentAlignment.BottomRight || itemAlign == ContentAlignment.MiddleRight || itemAlign == ContentAlignment.TopRight)
           {
               var needX = columns * (pictureSize.Width + 2 * pictureBorderWidth) + (columns - 1) * cellWidth;
               adjustX = this.Width - needX;
           }
            //初始化照片控件
           for (int row = 0; row < rowMax; row++)
            {
                for (int column = 0; column < Columns; column++)
                {
                    if (count == c)
                    {
                        return ;
                    }
                    UserPhotoItem2 p = new UserPhotoItem2();
                    p.ShowLabel = showLabel;
                    p.Size = pictureSize;

                    int width = pictureSize.Width + cellWidth;
                    int height = pictureSize.Height + cellHeight;
                    p.Location = new Point(column * width + pictureBorderWidth + adjustX, row * height + pictureBorderWidth + adjustY);
                    this.Controls.Add(p);
                    pics.Add(p);
                    c++;
                }
            }
        }