2009-08-20 4 views
0

私はGUIプログラミングに全く新しいので、ピクチャボックスのリストについては少し助けが必要です。.NETのコレクションとオブジェクトのメソッドへのアクセス

アイデアは、私にはピクチャボックスのリストがあるということです。ユーザーが1つをクリックすると、(たとえば)Fixed3Dに選択されたBorderStyleプロパティを変更し、残りのコレクションの境界をFixedSingle(またはそのようなもの)に変更したいと思います。このようなことをする正しい方法は何ですか?もっと大きな写真があると思います。あるクラスのメソッドを取得して、それに関する情報を持たずに別のメソッドを呼び出す方法はありますか?

class myPicture 
{ 
    private int _pictureNumber; 
    private PictureBox _box; 
    public myPicture(int order) 
    { 
    _box = new List<PictureBox>(); 
    _box.Click += new System.EventHandler(box_click); 
    _pictureNumber = order; 
    } 
    public void setBorderStyle(BorderStyle bs) 
    { 
    _box.BorderStyle = bs; 
    } 
    public void box_click(object sender, EventArgs e) 
    { 
    //here I'd like to call the set_borders from myPicturesContainer, but I don't know or have any knowledge of the instantiation 
    } 
} 

class myPicturesContainer 
{ 
    private List<myPicture> _myPictures; 
    //constructor and other code omitted, not really needed... 
    public void set_borders(int i) 
    { 
    foreach(myPicture mp in _MyPictures) 
     mp.setBorderStyle(BorderStyle.FixedSingle); 
    if(i>0 && _MyPictures.Count>=i) 
     _MyPictures[i].setBorderStyle(BorderStyle.Fixed3d); 
    } 
} 
+0

:ここ

は、私が何を意味するかの非常に簡単な例です。たとえば、WPFでは、プロパティのバインドやスタイル(および場合によってはテンプレート)を使用します。 –

答えて

0

あなたmyPictureクラスでClickedイベントを作成し、それがクリックされたときにイベントを発生させる必要があります。次に、のこのイベントに、myPictureのインスタンスごとに添付する必要があります。それは非常にあなたが使用しているものUIフレームワークに依存し

class myPicture 
{ 
    public event Action<Int32> Clicked = delegate { }; 

    private int _pictureNumber; 

    public void box_click(object sender, EventArgs e) 
    { 
     this.Clicked(this._pictureNumber); 
    } 
} 

class myPicturesContainer 
{ 
    private List<myPicture> _myPictures; 

    public void set_borders(int i) 
    { 
     foreach (myPicture mp in _myPictures) 
     { 
      mp.Clicked += pictureClick; 
     } 
    } 

    void pictureClick(Int32 pictureId) 
    { 
     // This method will be called and the pictureId 
     // of the clicked picture will be passed in 
    } 
} 
+0

それは完璧に働いた、ありがとう! – Diego