亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

.NET WinForm實(shí)現(xiàn)在listview中添加progressbar的方法

 更新時(shí)間:2017年05月19日 10:07:02   作者:何問起  
這篇文章主要介紹了.NET WinForm實(shí)現(xiàn)在listview中添加progressbar的方法,結(jié)合實(shí)例形式簡單分析了進(jìn)度條控件的添加與使用方法,需要的朋友可以參考下

本文實(shí)例講述了.NET WinForm實(shí)現(xiàn)在listview中添加progressbar的方法。分享給大家供大家參考,具體如下:

找了好長時(shí)間沒找到,后來索性自己寫了一個(gè):

首先,在往listview加載數(shù)據(jù)的事件里添加progressbar:

foreach (string d in arr)
{
    int index = lv.Items.Count + 1;
    item = new ListViewItem(new string[] { index.ToString(), d, "", "", "", "" });
    lv.Items.Add(item);
    float progress = 0;
    Rectangle SizeR = default(Rectangle);
    System.Windows.Forms.ProgressBar ProgBar = new System.Windows.Forms.ProgressBar();
    SizeR = item.SubItems[2].Bounds;
    SizeR.Width = lv.Columns[2].Width;
    ProgBar.Parent = lv;
    ProgBar.SetBounds(SizeR.X, SizeR.Y, SizeR.Width, SizeR.Height);
    ProgBar.Value = (int)progress;
    ProgBar.Visible = true;
    //取一個(gè)唯一的名字,以后好找
    ProgBar.Name = d + "progressbar";
}

然后在需要修改progressbar的值的地方設(shè)置它的值:

//循環(huán)listview上的所有控件,按名字找到progressbar
foreach (Control item in lv.Controls)
{
    if (item.Name == d.Name + "progressbar")
    {
      ProgressBar bar = (ProgressBar)item;
      bar.Value = (int)((d.Progress) * 100);
    }
}

其實(shí)我們只是把progressbar根據(jù)長寬高固定在了listview指定的格子里,如果我們拖動(dòng)listview中的列,格子的位置會(huì)發(fā)生改變,這時(shí)候需要修改對(duì)應(yīng)proressbar的位置,我們需要添加ColumnWidthChanging事件,在拖動(dòng)column的時(shí)候,progressbar會(huì)隨著改變位置:

private void lvt_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
  Rectangle SizeR = default(Rectangle);
  int width = e.NewWidth;
  foreach (Control item in lv.Controls)
  {
    //根據(jù)名字找到所有的progressbar
    if (item.Name.IndexOf("progressbar") >= 0)
    {
      ProgressBar bar = (ProgressBar)item;
      //Rectangle size=bar.Bounds;
      SizeR=bar.Bounds;
      //lv.Columns[2]是放置progressbar的地方
      SizeR.Width=lv.Columns[2].Width;
      bar.SetBounds(lv.Items[0].SubItems[2].Bounds.X, SizeR.Y, SizeR.Width, SizeR.Height);
      //bar.Width = width;
    }
  }
}

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《WinForm控件用法總結(jié)》、《C#窗體操作技巧匯總》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#常見控件用法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論