0

いくつかのグラフを描画するためのコントロールに取り組んでいます。この目的のために、PictureBox基本的に次の単純なクラスのリストからコントロールを派生させ、それにフィールドを追加したいと考えています。

public class Curve
{
     public List<PointF> DataPoints;
     public Color CurveColor;
     //and constructor and stuff
}

そして PictureBox クラス:

public class Graph : PictureBox
{
    List<Curve> Curves;
    //And some code to take care of drawing the curves
}

Curveクラスでオブジェクトが追加または削除されるたびに、Graph残りの曲線オブジェクトで自分自身を再描画するように、イベントをフックする方法はありますか?

ここでいくつかの詳細を見つけましたが、これはArrayList

4

1 に答える 1

5

1 つの方法は、ObservableCollection を Graph クラスに使用し、その CollectionChanged イベントをリッスンして、グラフを再描画することです。

public class Graph : PictureBox {
    ObservableCollection<Point> Curves;
    //And some code to take care of drawing the curves

    public Graph() {
      Curves.CollectionChanged += Curves_CollectionChanged;
    }

    void Curves_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
      Redraw();
    }
}
于 2012-07-14T22:59:12.377 に答える