0
我完全不熟悉GUI編程,需要一些圖片框的幫助。.NET集合和訪問對象方法
這個想法是,我有一個pictureboxes列表。當用戶點擊一個我想要的(例如)更改所選爲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);
}
}
這很大程度上取決於你所使用的UI框架。例如,在WPF中,您可以使用屬性綁定和樣式(可能還有模板)。 – 2009-08-20 20:38:17