Esempio n. 1
0
        /// <summary>
        /// Panel1当做画板,画出网格
        /// </summary>
        /// <param name="e"></param>
        /// <param name="_gh"></param>
        private void DrawGrids(PaintEventArgs e, GridHole _gh)
        {
            GridHole gridhole = _gh;
            int      type     = gridhole.Type;
            Pen      pen      = new Pen(Color.Black);

            switch (type)
            {
            case -1:
            {
                pen.Width = 1.5f;
                DrawRectangles(e.Graphics, pen, gridhole.Rect, gridhole.DridTitle);
                break;
            }

            case 0:
            {
                pen.Width = 1.0f;
                DrawRectangles(e.Graphics, pen, gridhole.Rect, gridhole.IsSelected);
                break;
            }

            case 1:
            {
                pen.Width = 1.5f;
                DrawRectangles(e.Graphics, pen, gridhole.Rect, gridhole.DridTitle);
                break;
            }

            case 2:
            {
                pen.Width = 1.5f;
                DrawRectangles(e.Graphics, pen, gridhole.Rect, 2);
                break;
            }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 初始化网格
        /// </summary>
        private void CreateGrid()
        {
            this.panel1.BackColor = Color.White;
            int RowH, ColW, _gridSpacing = 6;

            ColW   = ((this.panel1.Width) / _rowCount) - _gridSpacing;
            RowH   = ((this.panel1.Height) / _colCount) - _gridSpacing;
            m_Left = 0;
            m_Top  = 0;
            GridHole gridhole = new GridHole();

            gridhole.Type         = 2;
            gridhole.Rect         = new Rectangle(m_Left, m_Top, ColW, RowH);
            gridhole.DridLocation = "0";
            _Grids.Add(gridhole);
            //列头
            for (int i = 1; i < _rowCount; i++)
            {
                gridhole              = new GridHole();
                gridhole.Type         = -1;
                gridhole.DridTitle    = i.ToString();
                m_Left               += ColW + _gridSpacing;
                gridhole.Rect         = new Rectangle(m_Left, m_Top, ColW, RowH);
                gridhole.DridLocation = i.ToString();
                _Grids.Add(gridhole);
            }
            m_Left = 0;
            //行头
            for (int i = 1; i < _colCount; i++)
            {
                gridhole           = new GridHole();
                gridhole.Type      = 1;
                gridhole.DridTitle = i.ToString();
                m_Top                += RowH + _gridSpacing;
                gridhole.Rect         = new Rectangle(m_Left, m_Top, ColW, RowH);
                gridhole.DridLocation = i.ToString();
                _Grids.Add(gridhole);
            }

            m_Left = 0;
            m_Top  = 0;

            int RowLocation = 1, ColLocation = 1;

            for (int i = 0; i < (_rowCount - 1) * (_colCount - 1); i++)
            {
                if (i % (_rowCount - 1) == 0 && i == 0)
                {
                    m_Left       += ColW + _gridSpacing;
                    m_Top         = RowH + _gridSpacing;
                    gridhole      = new GridHole();
                    gridhole.Type = 0;
                    gridhole.Rect = new Rectangle(m_Left, m_Top, ColW, RowH);
                    string Loca = "1" + "|" + ColLocation.ToString();
                    gridhole.DridLocation = Loca;
                    _Grids.Add(gridhole);
                }
                else
                {
                    if (i % (_rowCount - 1) == 0)
                    {
                        m_Left = 0; m_Top += RowH + _gridSpacing; RowLocation += 1; ColLocation = 0;
                    }
                    m_Left       += ColW + _gridSpacing;
                    gridhole      = new GridHole();
                    gridhole.Type = 0;
                    gridhole.Rect = new Rectangle(m_Left, m_Top, ColW, RowH);
                    ColLocation++;
                    string Loca = RowLocation.ToString() + "|" + ColLocation.ToString();
                    gridhole.DridLocation = Loca;
                    _Grids.Add(gridhole);
                }
            }
        }