Example #1
0
        private void TableLayoutPaintBorder(object sender, PaintEventArgs e)
        {
            TableLayoutPanel table = ((TableLayoutPanel)sender);
            Graphics         g     = table.CreateGraphics();

            foreach (Control c in table.Controls)
            {
                Rectangle rec = c.Bounds;
                rec.Inflate(2, 2);
                ControlPaint.DrawBorder(g, rec, borderColor, ButtonBorderStyle.Solid);
            }
        }
Example #2
0
        // khởi tạo lưới khung
        public void InitTableLayout()
        {
            if (_tablelayout != null)
            {
                this.splitContainer2.Panel1.Controls.Remove(_tablelayout);
            }
            if (_mapController == null)
            {
                return;
            }
            else if (_mapController.TilesMap == null)
            {
                return;
            }
            int columns = this._mapController.TilesMap.Columns;
            int rows    = this._mapController.TilesMap.Rows;

            _tablelayout = new TableLayoutPanel();

            _tablelayout.ColumnCount = columns;
            // khởi tạo ma trận index
            // khởi tạo cột
            Size  tilesize   = MainForm.Settings.TileSize;
            float columnsize = 100.0f / columns;

            for (int i = 0; i < columns; i++)
            {
                var columnstyle = new ColumnStyle(SizeType.Absolute, tilesize.Width - 1);
                _tablelayout.ColumnStyles.Add(columnstyle);
            }
            // khởi tạo dòng
            _tablelayout.RowCount = rows;
            float rowsize = 100.0f / rows;

            for (int i = 0; i < rows; i++)
            {
                var rowstyle = new RowStyle(SizeType.Absolute, tilesize.Height - 1);
                _tablelayout.RowStyles.Add(rowstyle);
            }

            _tablelayout.BackColor       = Color.FromArgb(205, 205, 205);
            _tablelayout.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
            _tablelayout.Margin          = new System.Windows.Forms.Padding(5);
            _tablelayout.Name            = "map";

            _tablelayout.AutoSize    = true;
            _tablelayout.Paint      += _tablelayout_Paint;
            _tablelayout.MouseClick += TablelayoutMouseClick;
            this.splitContainer2.Panel1.Controls.Add(_tablelayout);
            this.splitContainer2.SplitterDistance = (int)(this.splitContainer2.Size.Height * 0.75);

            _tablelayout.MouseDown += TablelayoutMouseDown;
            _tablelayout.MouseUp   += TablelayoutMouseUp;

            // Khởi tạo graphics.
            _graphics = _tablelayout.CreateGraphics();
            var context = BufferedGraphicsManager.Current;

            context.MaximumBuffer = _tablelayout.Size + new Size(1, 1);
            _buffergraphics       = context.Allocate(_tablelayout.CreateGraphics(), new Rectangle(Point.Empty, _tablelayout.Size));

            this._mapController.Graphics = _buffergraphics.Graphics;
        }