有一个panel,里面放了若干个button按钮,按钮没有选中设置一个背景图片,按钮选中显示另一个背景图片,这样怎么样实现?
求各位大师指导!
求各位大师指导!
解决方案
10
用一个image作为button,实现click事件,改变image的image就简单了吧
10
扔一个 ImageList, 将你需要显示的图片都丢里面;
对应按钮对应状态的图片, 直接取对应图片索引
button1.Image = this.imageList1.Images[X];
对应按钮对应状态的图片, 直接取对应图片索引
button1.Image = this.imageList1.Images[X];
10
添加一个imagelist,里面放上图片
/// <summary> /// 当按钮得到焦点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Enter(object sender, EventArgs e) { button1.BackgroundImage = imageList1.Images[0]; } /// <summary> /// 当按钮失去焦点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Leave(object sender, EventArgs e) { button1.BackgroundImage = null; }
5
按钮只有点击,选中有什么意义
5
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
this.panel1.BackColor = Color.Red;
}
private void button1_Click(object sender, EventArgs e)
{
this.panel1.BackColor = Color.Blue;
}
试试这个
{
this.panel1.BackColor = Color.Red;
}
private void button1_Click(object sender, EventArgs e)
{
this.panel1.BackColor = Color.Blue;
}
试试这个