private void TileGridControl_MouseDown(object sender, MouseEventArgs e) { //this.Focus(); if (!this.ctrlPressed) { foreach (TileGridItem selItem in this.selectedItems.Values) { selItem.IsSelected = false; } selectedItems.Clear(); } double scaledValue = GetScaledScrollBarValue(); Point worldCoordinates = new Point(e.Location.X - rowHeaderWidth, e.Location.Y + (int)(scaledValue * (double)this.vScrollFactor) - (colHeaderHeight + colHeaderSpacer)); if (worldCoordinates.X < 0 || worldCoordinates.Y < 0) { return; } Point tileCoordinates = new Point(worldCoordinates.X / tileSize, worldCoordinates.Y / tileSize); TileGridItem clickedItem = this.GetItemAtTilePos(tileCoordinates); if (clickedItem != null) { clickedItem.IsSelected = !clickedItem.IsSelected; if (clickedItem.IsSelected) { this.selectedItems.Add(clickedItem.Row, clickedItem); } else { this.selectedItems.Remove(clickedItem.Row); } } }
private void ReDrawItem(TileGridItem item) { if (itemImage == null) { return; } using (Graphics graphics = Graphics.FromImage(itemImage)) { DrawItem(graphics, item, new Point(0, 0)); } }
private void DrawItem(Graphics graphics, TileGridItem item, Point offset) { Rectangle tile = new Rectangle(item.Col * tileSize + offset.X, item.Row * tileSize + offset.Y, item.ColSpan * tileSize, item.RowSpan * tileSize); Color tileColor = item.IsSelected ? item.SelectedColor : item.BackColor; SolidBrush tileBrush = new SolidBrush(tileColor); graphics.FillRectangle(tileBrush, tile); tileBrush.Color = item.ForeColor; graphics.DrawLine(new Pen(tileBrush), new Point(tile.Left, tile.Bottom - 1), new Point(tile.Right - 1, tile.Bottom - 1)); graphics.DrawString(item.Text, this.Font, tileBrush, new PointF(10f + tile.X, 10f + tile.Y)); }