求大哥们解答,C#2010中怎么用button 控件控制picturebox中图片调换
2个回答
2017-06-02
展开全部
1.Flat button
用这个方法,前提是要把button的type设置为Flat
复制代码 代码如下:
button1.TabStop = false;button1.FlatAppearance.BorderSize = 0;
button1.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); //设置边框的颜色Transparent
button1.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 255, 255, 255); //设置鼠标经过时候的背景颜色Transparent
button1.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 255, 255, 255); //设置鼠标按下时候的背景颜色Transparent
这样按钮的效果图如下
后面的颜色是窗体的颜色不是按钮的颜色。
接下来响应点击事件。
复制代码 代码如下:
//鼠标落下设置一张图片
private void button1_MouseDown(object sender, MouseEventArgs e)
{
this.button1.Image = Image.FromFile(@"../../images/close_click.png");
}
//鼠标弹起恢复原来图片
private void button1_MouseUp(object sender, MouseEventArgs e)
{
this.button1.Image = Image.FromFile(@"../../images/close_default.png");
}
//响应点击事件
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("I'm normal button");
}
2.用pictureBox
复制代码 代码如下:
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox2.Image = Image.FromFile(@"../../images/close_click.png");
}
private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
{
this.pictureBox2.Image = Image.FromFile(@"../../images/close_default.png");
}
private void pictureBox2_Click(object sender, EventArgs e)
{
MessageBox.Show("I'm closed");
用这个方法,前提是要把button的type设置为Flat
复制代码 代码如下:
button1.TabStop = false;button1.FlatAppearance.BorderSize = 0;
button1.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); //设置边框的颜色Transparent
button1.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 255, 255, 255); //设置鼠标经过时候的背景颜色Transparent
button1.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 255, 255, 255); //设置鼠标按下时候的背景颜色Transparent
这样按钮的效果图如下
后面的颜色是窗体的颜色不是按钮的颜色。
接下来响应点击事件。
复制代码 代码如下:
//鼠标落下设置一张图片
private void button1_MouseDown(object sender, MouseEventArgs e)
{
this.button1.Image = Image.FromFile(@"../../images/close_click.png");
}
//鼠标弹起恢复原来图片
private void button1_MouseUp(object sender, MouseEventArgs e)
{
this.button1.Image = Image.FromFile(@"../../images/close_default.png");
}
//响应点击事件
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("I'm normal button");
}
2.用pictureBox
复制代码 代码如下:
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox2.Image = Image.FromFile(@"../../images/close_click.png");
}
private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
{
this.pictureBox2.Image = Image.FromFile(@"../../images/close_default.png");
}
private void pictureBox2_Click(object sender, EventArgs e)
{
MessageBox.Show("I'm closed");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询