Ejemplo n.º 1
0
        /// <summary>
        /// 动态布局
        /// </summary>
        /// <param name="layoutPanel">布局面板</param>
        /// <param name="Row">行</param>
        /// <param name="Col">列</param>
        private void DynamicLayout(TableLayoutPanel layoutPanel, Color bColor, int size = 32)
        {
            layoutPanel.Controls.Clear();
            layoutPanel.RowStyles.Clear();
            layoutPanel.ColumnStyles.Clear();
            layoutPanel.RowCount = Row + 1;    //设置分成几行
            float pRow    = Convert.ToSingle((100 / Row).ToString("0.00"));
            float pColumn = Convert.ToSingle((100 / Col).ToString("0.00"));

            for (int i = 0; i < Row; i++)
            {
                layoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, size));
            }
            layoutPanel.ColumnCount = Col + 1;    //设置分成几列
            for (int i = 0; i < Col; i++)
            {
                layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, size));
            }
            for (int i = 0; i < Row; i++)
            {
                for (int j = 0; j < Col; j++)
                {
                    uButton btn = new uButton();
                    btn.Anchor    = AnchorStyles.None;
                    btn.Margin    = new Padding(0, 0, 0, 0);
                    btn.Dock      = DockStyle.Fill;
                    btn.BackColor = Color.Black;
                    btn.Font      = new Font("宋体", 7.5F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(134)));
                    btn.Name      = i.ToString() + "_" + j.ToString();
                    Index pos = new Index(i, j);
                    int   num = t.FindPos(pos);
                    if (num > -1)
                    {
                        t.dic_Index[num].SetColor(bColor);//初始化颜色
                    }
                    //如果是显示模式
                    if (bShowModel)
                    {
                        //屏蔽的点不显示名称
                        if (num < 0)
                        {
                            btn.Text = "";
                            SetBtnColor(btn, backColor);
                        }
                        else
                        {
                            //不屏蔽的点显示顺序号
                            btn.Text = num.ToString();
                            SetBtnColor(btn, bColor);
                        }
                    }
                    else
                    {
                        if (num < 0)
                        {
                            SetBtnColor(btn, backColor);
                        }
                        else
                        {
                            SetBtnColor(btn, bColor);
                        }
                        btn.Text = i.ToString() + "," + j.ToString();
                    }

                    btn.Click += new EventHandler(this.label_Click);
                    layoutPanel.Controls.Add(btn, j, i);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 动态布局
        /// </summary>
        /// <param name="layoutPanel">布局面板</param>
        /// <param name="Row">行</param>
        /// <param name="Col">列</param>
        private void DynamicLayout(TableLayoutPanel layoutPanel, Color bColor)
        {
            layoutPanel.Controls.Clear();
            layoutPanel.RowStyles.Clear();
            layoutPanel.ColumnStyles.Clear();
            layoutPanel.RowCount = Row + 1;    //设置分成几行
            float pRow    = Convert.ToSingle((100 / Row).ToString("0.00"));
            float pColumn = Convert.ToSingle((100 / Col).ToString("0.00"));

            for (int i = 0; i < Row + 1; i++)
            {
                if (i == Row)
                {
                    layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 0));
                }
                else
                {
                    layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
                }
            }
            layoutPanel.ColumnCount = Col + 1;    //设置分成几列
            for (int i = 0; i < Col + 1; i++)
            {
                if (i == Col)
                {
                    layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 0));
                }
                else
                {
                    layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                }
            }
            for (int i = 0; i < Row; i++)
            {
                for (int j = 0; j < Col; j++)
                {
                    Button btn = new Button();
                    btn.Anchor    = AnchorStyles.None;
                    btn.Margin    = new Padding(0, 0, 0, 0);
                    btn.Dock      = DockStyle.Fill;
                    btn.TextAlign = ContentAlignment.MiddleCenter;
                    btn.FlatAppearance.BorderSize = 0;
                    btn.FlatStyle = FlatStyle.Flat;

                    btn.BackgroundImageLayout = ImageLayout.Stretch;
                    btn.Name = i.ToString() + "_" + j.ToString();
                    Index pos = new Index(i, j);
                    int   num = t.FindPos(pos);
                    if (num > -1)
                    {
                        t.dic_Index[num].SetColor(bColor);//初始化颜色
                    }
                    //如果是显示模式
                    if (bShowModel)
                    {
                        //屏蔽的点不显示名称
                        if (num < 0)
                        {
                            btn.Text = "";
                            SetBtnColor(btn, backColor);
                        }
                        else
                        {
                            //不屏蔽的点显示顺序号
                            btn.Text = num.ToString();
                            SetBtnColor(btn, bColor);
                        }
                    }
                    else
                    {
                        if (num < 0)
                        {
                            SetBtnColor(btn, backColor);
                        }
                        else
                        {
                            SetBtnColor(btn, bColor);
                        }
                        btn.Text = i.ToString() + "," + j.ToString();
                    }

                    btn.Click += new System.EventHandler(this.label_Click);
                    layoutPanel.Controls.Add(btn, j, i);
                }
            }
        }