基本クラスDockedToolWindow:Formと、DockedToolWindowから派生した多くのクラスがあります。DockedToolWindowオブジェクトにイベントを保持して割り当てるコンテナクラスがありますが、子クラスからイベントを呼び出したいと思います。
このMSDNサイトから指示されていることを実装する方法について実際に質問があります。以下のこのセクションは私に問題を与えています:
// The event. Note that by using the generic EventHandler<T> event type
// we do not need to declare a separate delegate type.
public event EventHandler<ShapeEventArgs> ShapeChanged;
public abstract void Draw();
//The event-invoking method that derived classes can override.
protected virtual void OnShapeChanged(ShapeEventArgs e)
{
// Make a temporary copy of the event to avoid possibility of
// a race condition if the last subscriber unsubscribes
// immediately after the null check and before the event is raised.
EventHandler<ShapeEventArgs> handler = ShapeChanged;
if (handler != null)
{
handler(this, e);
}
}
この例はコンパイルして機能しますが、「ShapeChanged」を「Move」(Formから派生して取得したイベント)に置き換えると、+=または-=がないと右側にMoveを設定できないというエラーが表示されます。ShapeEventArgs汎用タグも削除しました。
これが機能しない理由について何か刺激はありますか?クラス内で宣言されたイベントと継承されたイベントの違いは何ですか?