Exemplo n.º 1
0
        public static void PaintBlock(GridBlock gridBlock)
        {
            if (GridBoard == null)
            {
                return;
            }
            if (GridGraphics == null)
            {
                return;
            }
            int x = BlockOffset;
            int y = BlockOffset;

            //根据序号取得当前Index所对应位置
            //if (GridColumnFirst)
            //{
            x += (gridBlock.BlockColumnIndex.Equals(0) ? (gridBlock.BlockIndex % GridColumnCount) : gridBlock.BlockColumnIndex) * (BlockWidth + BlockOffset);
            y += (gridBlock.BlockRowIndex.Equals(0) ? (gridBlock.BlockIndex / GridColumnCount) : gridBlock.BlockRowIndex) * (BlockHeight + BlockOffset);
            //}
            //else
            //{
            //    x += (gridBlock.BlockIndex / GridRowCount) * (BlockWidth + BlockOffset);
            //    y += (gridBlock.BlockIndex % GridRowCount) * (BlockHeight + BlockOffset);
            //}
            //先画一个大的底块
            GridGraphics.FillRectangle(new SolidBrush(gridBlock.BorderColor), new Rectangle(x, y, BlockWidth, BlockHeight));
            x = x + BorderSize;
            y = y + BorderSize;
            int w = BlockWidth - (BorderSize * 2);
            int h = BlockHeight - (BorderSize * 2);

            //再画块
            gridBlock.BlockSize     = new Size(w, h);
            gridBlock.BlockLocation = new Point(x, y);
            GridGraphics.FillRectangle(new SolidBrush(gridBlock.BlockColor), new Rectangle(x, y, w, h));
            //写入文字
            GridGraphics.DrawString(gridBlock.BlockText, BlockFont, Brushes.Black, new Rectangle(x, y, w, h));
            // GridBoard.Refresh();
        }
Exemplo n.º 2
0
 public static void InitializeGrid(Control gridBoard)
 {
     index     = 0;
     GridBoard = gridBoard;
     if (GridBoard == null)
     {
         return;
     }
     GridGraphics = GridBoard.CreateGraphics();
     GridGraphics.Clear(BackgroundColor);
     for (int i = 0; i < GridColumnCount; i++)
     {
         for (int j = 0; j < GridRowCount; j++)
         {
             GridBlock gridBlock = new GridBlock();
             gridBlock.BlockIndex = index;
             index += 1;
             gridBlock.BlockColor = BlockColor;
             gridBlock.BlockText  = "";//gridBlock.BlockIndex.ToString();
             PaintBlock(gridBlock);
         }
     }
 }