DataGridView顯示進度條列

來源:互聯網
上載者:User

標籤: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屬性:

 

運行起來,大功告成!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.