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