找了好长时间没找到,后来索性自己写了一个:

首先,在往listview加载数据的事件里添加progressbar:

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

然后在需要修改progressbar的值的地方设置它的值:

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

其实我们只是把progressbar根据长宽高固定在了listview指定的格子里,如果我们拖动listview中的列,格子的位置会发生改变,这时候需要修改对应proressbar的位置,我们需要添加ColumnWidthChanging事件,在拖动column的时候,progressbar会随着改变位置:

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

.NET winform 在listview中添加progressbar的更多相关文章

  1. Android 如何在 ListView 中更新 ProgressBar 进度

    =======================ListView原理============================== Android 的 ListView 的原理打个简单的比喻就是: 演员演 ...

  2. 往另外1个ListView中添加当前选中的项目

      //往另外1个ListView中添加当前选中的项目   function AddSelItems(listview1:TListView;ListView2:TListView):Boolean; ...

  3. winform实现listview中combox

    一.概要 因为要在项目中要在ListView中实现下拉框选择,用DataGrid的话,一个不美观,二个绑定数据麻烦,参考网上一种做法,就是单击ListView时,判断单击的区域,然后将Combox控件 ...

  4. WPF: 在ListView中添加Checkbox列表

    描述:ListView是WPF中动态绑定工具的数据容器,本文实现了一个在ListView中显示的供用户选择的列表项目,并且控制列表中选择的项目数量,即实现单选. XAML中创建ListView,代码如 ...

  5. winfrom如何在listview中添加控件

    private Button btn = new Button(); private void Form1_Load(object sender, EventArgs e) { ListViewIte ...

  6. Delphi - 在ListView中添加一个进度条

    // 相关定义 Type TListData = Record FileName: String; Percent: Integer; End; PListData = ^TListData; // ...

  7. ListView中添加ScrollView只显示一两行的问题

    将ListView改为继承NoScrollListView package com.example.brtz.widget; import android.content.Context; impor ...

  8. Android ListView中添加不同的多种布局

    最近做项目要使用ListView加载不同的布局,由于自己写的代码不能贴出,故找了一篇自认为比较好的blog给分享出来,希望对用到此项技术的同学有点帮助. http://logc.at/2011/10/ ...

  9. 在ListView中添加EditText丢失光标问题解决

    <ListView    android:id="@android:id/list"     android:layout_height="fill_parent& ...

随机推荐

  1. Lua----注意事项

    前言:Lua相对一般的语言相对简单,有c基础看一遍就差不多了.一般的代码都能够看懂.但是Lua也有一些自己的特点,区别与其他语言,这里需要注意一下. 1.数组下标 在Lua中数组下标是从1开始计数的. ...

  2. d3可视化实战01:理解SVG元素特性

    一. SVG简介 ————————————————————————————————————————————————————————————————— SVG是一种和图像分辨率无关的矢量图形格式,它使用 ...

  3. hdu 2992 Hotel booking

    http://acm.hdu.edu.cn/showproblem.php?pid=2992 #include <cstdio> #include <cstring> #inc ...

  4. 玩转Google开源C++单元测试框架Google Test系列(转载)

    越来越多公司采用敏捷开发,单元和回归测试越来越重要,GTest作为最佳C++单元测试工具越来越多的被使用.转自 http://www.cnblogs.com/coderzh/archive/2009/ ...

  5. MFC的GUI窗口使用Console输出函数printf

    在GUI程序中使用printf函数: #include <io.h> #include <fcntl.h> void InitConsole() { ; FILE* fp; A ...

  6. Why SignalR does not use WebSockets?

    Why SignalR does not use WebSockets?   As you probably know SignalR supports multiple transports. Th ...

  7. windows 10是如何做到全平台统一的?

    1.EXE本身就是个容器,它可以在ARM平台上包含ARM的native code执行,也可以在x86平台上包含x86的native code执行,本质上无差别(所以麻烦那些说EXE不能在ARM平台上运 ...

  8. HDOJ 1420 Prepared for New Acmer(DP)

    Problem Description 集训进行了将近2个礼拜,这段时间以恢复性训练为主,我一直在密切关注大家的训练情况,目前为止,对大家的表现相当满意,首先是绝大部分队员的训练积极性很高,其次,都很 ...

  9. Andoid实现手动绘图

    public class MainActivity extends Activity { int width,height; private GameView gameview; private Ca ...

  10. HDU_1238——最大子串搜索

    Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...