将ProgressBar插入ListView中

先见ProgressBar插入ListView中去。

progressBar = new Progressbar();
Rectangle rect = item.SubItems[2].Bounds;
progressBar.Size = new Size(rect.Width, rect.Height);
progressBar.Top = rect.Top;
progressBar.Left = rect.Left;

并在ListView的ColumnWidthChanged事件中添加如下代码:

Rectangle rect = this.lstViewFiles.Items[0].SubItems[2].Bounds;
foreach (ProgressBar bar in this.lstViewFiles.Controls)
{
    bar.Width = rect.Width;
    bar.Left = rect.Left;
}

 

我们发现,当ListView出现滚动条时,Progressbar无法移动,我们得重新修改下ListView。

首先,创建一个名为ListViewExtensions的类,该类继承于ListView,类中包含一个ListView所在窗口类的引用,并在类中重写WndProc方法。

public class ListViewExtension : ListView
{
    /// <summary>
    /// Upload Form
    /// </summary>
    private UploadForm uploadForm;
 
    /// <summary>
    /// Cotr
    /// </summary>
    /// <param name="from">UploadForm</param>
    public ListViewExtension(UploadForm from)
    {
        uploadForm = from;
    }
 
    /// <summary>
    /// WndProc
    /// </summary>
    /// <param name="m">Message</param>
    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
 
        if (m.Msg == 0x0114 || m.Msg == 0x0115)
        {
            Rectangle rect = this.Items[0].SubItems[2].Bounds;
            this.BeginUpdate();
            //移动ProgressBar的位置
            foreach (ProgressBar bar in this.Controls)
            {
                bar.Left = rect.Left;
                bar.Width = rect.Width;
            }
            this.EndUpdate();
        }
    }
}

效果图如下:

image

转载于:https://www.cnblogs.com/PorcellioQian/archive/2009/11/04/1596117.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值