-1
私はそれを理解しようとしていますが、それは容易ではありません。私はクラスのトップで : 私はコンストラクタに続いonSearchProgress進捗レポートイベントとハンドラを作成するにはどうすればよいですか?
private EventHandler onSearchComplete;
private EventHandler onSearchProgress;
を追加: IはonSearchProgress =新しいイベントハンドラ(OnSearchProgress)を加え、
public DirectorySearcher()
{
listBox = new ListBox();
listBox.Dock = DockStyle.Fill;
Controls.Add(listBox);
fileListDelegate = new FileListDelegate(AddFiles);
onSearchComplete = new EventHandler(OnSearchComplete);
onSearchProgress = new EventHandler(OnSearchProgress);
}
その後
public event EventHandler SearchComplete;
public event EventHandler SearchProgress;
これは私が報告として送信し、Form1でそれを取得したい部分です:
public int countf = 0;
public void AddFiles(string[] files, int startIndex, int count)
{
while (count-- > 0)
{
listBox.Items.Add(files[startIndex + count]);
countf++;
textlabel.Text = countf.ToString();
}
}
そして
private void OnSearchProgress(object sender, EventArgs e)
{
SearchProgress(sender, e);
}
を今すぐForm1のトップに:
Form1のコンストラクタでprivate DirectorySearcher directorySearcher;
:
public Form1()
{
InitializeComponent();
directorySearcher.SearchProgress += DirectorySearcher_SearchProgress;
}
そして
private void DirectorySearcher_SearchProgress(object sender, EventArgs e)
{
}
しかし、どのように私はクラスから報告すれば、どのように私はイベントでのForm1のレポートを得るのですか?たとえば、form1のようなもの:
多分、複数のレポートをクラスに追加して、Form1で複数のラベルを更新することができます。
private void DirectorySearcher_SearchProgress(object sender, EventArgs e)
{
label1.Text = e.textlabel;
label2.Text = e.textlabel1;
int counting = e.counter;
}