先上图在说,第二列中图片和文字的样式
1、需要重写DataGridViewTextBoxColumn,新建类TextAndImageColumn.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Windows.Forms; 6 using System.Drawing; 7 8 namespace DataGridViewTest 9 { 10 public class TextAndImageColumn : DataGridViewTextBoxColumn 11 { 12 private Image imageValue; 13 private Size imageSize; 14 15 public TextAndImageColumn() 16 { 17 this.CellTemplate = new TextAndImageCell(); 18 } 19 20 public override object Clone() 21 { 22 TextAndImageColumn c = base.Clone() as TextAndImageColumn; 23 c.imageValue = this.imageValue; 24 c.imageSize = this.imageSize; 25 return c; 26 } 27 28 public Image Image 29 { 30 get { return this.imageValue; } 31 set 32 { 33 if (this.Image != value) 34 { 35 this.imageValue = value; 36 this.imageSize = value.Size; 37 38 if (this.InheritedStyle != null) 39 { 40 Padding inheritedPadding = this.InheritedStyle.Padding; 41 this.DefaultCellStyle.Padding = new Padding(imageSize.Width, 42 inheritedPadding.Top, inheritedPadding.Right, 43 inheritedPadding.Bottom); 44 } 45 } 46 } 47 } 48 private TextAndImageCell TextAndImageCellTemplate 49 { 50 get { return this.CellTemplate as TextAndImage