想写一个容器类,底层是一张很大的图片,用作地图的底层。上面可以有小图片,button,label等控件,这些控件在整个类运动时相对与底层的图片是不动的。不知道这样的类该怎么写。我现在已经实现底层的大图片,但是在上面再添加控件就实现不了,而且底层的图片不是arraylist中。下面代码是我这个类的基本代码,不知道该如何改。求助 class Map : Control
{
//主背景图片
public PictureBox _pbx = new PictureBox();
private ArrayList conlist; //图片路径
private string _picpath;
public string Picpath
{
get
{
return _picpath;
}
set
{
_picpath = value;
try
{
FileStream fs = new FileStream(_picpath,FileMode.Open);
_pbx.Image = Image.FromStream(fs);
fs.Close();
}
catch (Exception e)
{
MessageBox.Show("装载图片失败:" + e.ToString());
}
}
}
//构造函数
public Map(string picpath)
{
try
{
_picpath = picpath;
FileStream fs = new FileStream(_picpath, FileMode.Open);
_pbx.Image = Image.FromStream(fs);
//fs.Close();
}
catch (Exception e)
{
MessageBox.Show("装载图片失败:" + e.ToString());
}
_pbx.SizeMode = PictureBoxSizeMode.AutoSize;
_pbx.Top = 0;
_pbx.Left = 0;
this.Width = _pbx.Width;
this.Height = _pbx.Width;
this.Controls.Add(_pbx);
}
}
{
//主背景图片
public PictureBox _pbx = new PictureBox();
private ArrayList conlist; //图片路径
private string _picpath;
public string Picpath
{
get
{
return _picpath;
}
set
{
_picpath = value;
try
{
FileStream fs = new FileStream(_picpath,FileMode.Open);
_pbx.Image = Image.FromStream(fs);
fs.Close();
}
catch (Exception e)
{
MessageBox.Show("装载图片失败:" + e.ToString());
}
}
}
//构造函数
public Map(string picpath)
{
try
{
_picpath = picpath;
FileStream fs = new FileStream(_picpath, FileMode.Open);
_pbx.Image = Image.FromStream(fs);
//fs.Close();
}
catch (Exception e)
{
MessageBox.Show("装载图片失败:" + e.ToString());
}
_pbx.SizeMode = PictureBoxSizeMode.AutoSize;
_pbx.Top = 0;
_pbx.Left = 0;
this.Width = _pbx.Width;
this.Height = _pbx.Width;
this.Controls.Add(_pbx);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货