C#委托实现进度条模拟(和委托1.0到3.0的写法)

//委托的定义类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace CopyWindowsForms
{
public delegate void CopyHand(int OpenStr,int SavaStr);
public class CopyHandle
{
public CopyHand CopyHandEvent { get; set; }
public void Copy()
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(200);
if (CopyHandEvent != null)
CopyHandEvent(i + 1, 100);
}
}
}
}//WinFrom文件CS文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CopyWindowsForms
{
public partial class CopyForm : Form
{
CopyHandle cp = new CopyHandle();//实例化类
public CopyForm()
{
InitializeComponent();
}

private void OpenButt_Click(object sender, EventArgs e)
{
//委托1.0
//cp.CopyHandEvent = new CopyHand(CopyHands);


//委托2.0【匿名方法】
//cp.CopyHandEvent = delegate(int i, int cout)
//{
// pb.Maximum = cout;
// pb.Value = i;
//};


//委托3.0
cp.CopyHandEvent = (i, cout) =>
{
pb.Maximum = cout;
pb.Value = i;
};
cp.Copy();
}
public void CopyHands(int i, int cout)
{
pb.Maximum = cout;
pb.Value = i;
}
}
}

模拟进度条委托方法使用1.0——3.0写法下载

http://115.com/file/aq1o5gqv

posted @ 2011-11-15 15:42  暗黑地狱风  阅读(412)  评论(0编辑  收藏  举报