以下のコードを投稿してください。foo1からプログレスバーを更新します。 私は イベントハンドラを設定するには
class Foo : Form // implements progressbar
{
IFoo foo = new Foo1()
// this will not do:
ProgressBarEventHandler = new EventUpdateProgressBar(this.UpdateProgressBar);
UpdateProgressBar() { }
}
public delegate void EventUpdateProgressBar();
class FooBase
{
public EventUpdateProgressBar ProgressBarEventHandler;
protected virtual void UpdateProgressBar()
{
if (ProgressBarEventHandler != null)
ProgressBarEventHandler();
}
}
class Foo1 : IFoo,FooBase { base.UpdateProgressBar() }
class Foo2 : IFoo,FooBase {}
interface IFoo {}
はFoo
でのEventHandlerを実装することができないんだ。この作業を取得する方法はありますかより良い方法はありますか?
正確な問題は何ですか?このコードでは例外がありますか? –
Foo ProgressBarEventHandlerが存在しないため、コンパイルされません。 – aw48
Fooの奇妙な宣言のため、最初はコンパイルされません。 Fooはクラスとして宣言されていますが、メソッドのように本体にコードが含まれています。 EventUpdateProgressBarに来る前に、この問題を修正してください。 –