没有蠢问题(1):1个按钮,1张图...100个按钮,100张...,Www我和你拼了!
问题:用按钮来控制图的显示
一个按钮一张图
private void Button1_Click(object sender, EventArgs e)
{
this.pic1.Visible = true;
}
{
this.pic1.Visible = true;
}
.....
四个按钮四张图
private void Button1_Click(object sender, EventArgs e)
{
this.pic1.Visible = true;
this.pic2.Visible = false;
this.pic3.Visible = false;
this.pic4.Visible = false;
}
private void Button2_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.pic2.Visible = true;
this.pic3.Visible = false;
this.pic4.Visible = false;
}
private void Button3_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.pic2.Visible = false;
this.pic3.Visible = true;
this.pic4.Visible = false;
}
private void Button4_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.tips2.Visible = false;
this.pic3.Visible = false;
this.pic4.Visible = true;
}
{
this.pic1.Visible = true;
this.pic2.Visible = false;
this.pic3.Visible = false;
this.pic4.Visible = false;
}
private void Button2_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.pic2.Visible = true;
this.pic3.Visible = false;
this.pic4.Visible = false;
}
private void Button3_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.pic2.Visible = false;
this.pic3.Visible = true;
this.pic4.Visible = false;
}
private void Button4_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.tips2.Visible = false;
this.pic3.Visible = false;
this.pic4.Visible = true;
}
......
100个按钮100张图
Www我和你拼了!
private void Button1_Click(object sender, EventArgs e)
{
this.pic1.Visible = true;
this.pic2.Visible = false;
this.pic3.Visible = false;
this.pic4.Visible = false;
this.pic5.Visible = false;
}
private void Button2_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.pic2.Visible = true;
this.pic3.Visible = false;
this.pic4.Visible = false;
}
累并快乐着
{
this.pic1.Visible = true;
this.pic2.Visible = false;
this.pic3.Visible = false;
this.pic4.Visible = false;
this.pic5.Visible = false;
}
private void Button2_Click(object sender, EventArgs e)
{
this.pic1.Visible = false;
this.pic2.Visible = true;
this.pic3.Visible = false;
this.pic4.Visible = false;
}
累并快乐着
不要以为上面是说笑而已,我看很多人都是这么干的!
同学,你有什么好的做法吗?
思路1:各家自扫门前雪,不管人家瓦上霜。
public class MyBotton : System.Windows.Forms.Button
{
/// <summary>
/// the shared showed pic
/// </summary>
private static System.Windows.Forms.PictureBox _picShowed = null;
private static System.Windows.Forms.PictureBox PicShowed
{
set
{
if (_picShowed != null)
{
//set to not show
_picShowed.Visible = false;
}
//set the goloble value
_picShowed = value;
if (_picShowed != null)
{
//set to show
_picShowed.Visible = true;
}
}
}
/// <summary>
/// my own pic
/// </summary>
private System.Windows.Forms.PictureBox _myPic = null;
public System.Windows.Forms.PictureBox MyPic
{
get
{
return _myPic;
}
set
{
_myPic = value;
}
}
/// <summary>
/// override click event
/// </summary>
/// <param name="e"></param>
protected override void OnClick(EventArgs e)
{
PicShowed = _myPic;
base.OnClick(e);
}
}
{
/// <summary>
/// the shared showed pic
/// </summary>
private static System.Windows.Forms.PictureBox _picShowed = null;
private static System.Windows.Forms.PictureBox PicShowed
{
set
{
if (_picShowed != null)
{
//set to not show
_picShowed.Visible = false;
}
//set the goloble value
_picShowed = value;
if (_picShowed != null)
{
//set to show
_picShowed.Visible = true;
}
}
}
/// <summary>
/// my own pic
/// </summary>
private System.Windows.Forms.PictureBox _myPic = null;
public System.Windows.Forms.PictureBox MyPic
{
get
{
return _myPic;
}
set
{
_myPic = value;
}
}
/// <summary>
/// override click event
/// </summary>
/// <param name="e"></param>
protected override void OnClick(EventArgs e)
{
PicShowed = _myPic;
base.OnClick(e);
}
}