Skip to content

Instantly share code, notes, and snippets.

@WildGenie
Created January 16, 2017 01:52
Show Gist options
  • Save WildGenie/24253d5c87cb9be190d773068c0477ae to your computer and use it in GitHub Desktop.
Save WildGenie/24253d5c87cb9be190d773068c0477ae to your computer and use it in GitHub Desktop.
#r "System.Windows.Forms"
#r "System.Drawing"
using System.Windows.Forms;
using System.Drawing;
using System;
Application.Run(new Form1());
public class Form1 : Form
{
private DataGridViewEx dataGridView1 = new DataGridViewEx();
DataGridViewComboBoxColumn comboBoxColumn;
DataGridViewComboBoxColumn comboBoxDetailColumn;
public Form1()
{
this.Load += FormLoad;
this.Controls.Add(dataGridView1);
}
private void AddColorColumn()
{
comboBoxColumn = new DataGridViewComboBoxColumn();
comboBoxColumn.Items.AddRange(
Color.Red, Color.Yellow, Color.Green, Color.Blue);
comboBoxColumn.ValueType = typeof(Color);
dataGridView1.Columns.Add(comboBoxColumn);
comboBoxDetailColumn = new DataGridViewComboBoxColumn();
comboBoxDetailColumn.ValueType = typeof(Color);
dataGridView1.Columns.Add(comboBoxDetailColumn);
}
private void FormLoad(object sender, EventArgs e)
{
AddColorColumn();
dataGridView1.BackgroundImage = Image.FromFile(
"C:\\Windows\\Web\\Screen\\img103.png");
dataGridView1.SetCellsTransparent();
}
}
public class DataGridViewEx : DataGridView
{
private Image _backgroundPic;
public override Image BackgroundImage
{
get { return _backgroundPic; }
set { _backgroundPic = value; }
}
protected override void PaintBackground(System.Drawing.Graphics graphics,
System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle gridBounds)
{
base.PaintBackground(graphics, clipBounds, gridBounds);
if (((this.BackgroundImage != null)))
{
graphics.FillRectangle(Brushes.Black, gridBounds);
graphics.DrawImage(this.BackgroundImage, gridBounds);
}
}
public void SetCellsTransparent()
{
this.EnableHeadersVisualStyles = false;
this.ColumnHeadersDefaultCellStyle.BackColor = Color.Transparent;
this.RowHeadersDefaultCellStyle.BackColor = Color.Transparent;
foreach (DataGridViewColumn col in this.Columns)
{
col.DefaultCellStyle.BackColor = Color.Transparent;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment