標籤:datagridview style blog class code java
先看看效果,如果感興趣,繼續往下看……
效果如所示:
DataGridView裡沒有Pragress列,但有Image列,有了它我們可以自己繪圖來實現進度條。其實實現起來並不困難。
首先在實體類增加Image類型的屬性,在get裡繪製進度條圖片:
using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Drawing2D;using System.Linq;using System.Text;namespace DataGridViewProgress{ public class UserInfo { public string UserName { get; set; } public string Addr { get; set; } public int Press { get; set; } //進度條圖片屬性 public Image PressImg { get { Bitmap bmp = new Bitmap(104, 30); //這裡給104是為了左邊和右邊空出2個像素,剩餘的100就是百分比的值 Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); //背景填白色 //g.FillRectangle(Brushes.Red, 2, 2, this.Press, 26); //普通效果 //填滿漸層效果 g.FillRectangle(new LinearGradientBrush(new Point(30, 2), new Point(30, 30), Color.Black, Color.Gray), 2, 2, this.Press, 26); return bmp; } } }}
然後在DataGridView裡添加圖片列並綁定DataPropertyName屬性:
運行起來,大功告成!