C# 点击图片放大 ,再点就变回原大小 也就是实现点击查看大图。图片是放在pictureBox里的
3个回答
展开全部
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
if (this.pictureBox1.Width == 150)
{
this.pictureBox1.SetBounds(this.pictureBox1.Location.X - 75, this.pictureBox1.Location.Y - 75, 300, 300);
}
else
{
this.pictureBox1.SetBounds(this.pictureBox1.Location.X + 75, this.pictureBox1.Location.Y +75, 150, 150);
}
}
150,300 是大小 你自己设置。 在pictureBox的 MouseClick事件添加代码。
{
if (this.pictureBox1.Width == 150)
{
this.pictureBox1.SetBounds(this.pictureBox1.Location.X - 75, this.pictureBox1.Location.Y - 75, 300, 300);
}
else
{
this.pictureBox1.SetBounds(this.pictureBox1.Location.X + 75, this.pictureBox1.Location.Y +75, 150, 150);
}
}
150,300 是大小 你自己设置。 在pictureBox的 MouseClick事件添加代码。
追问
行了 thx
展开全部
boolean a=true;
private void button2_Click(object sender, EventArgs e)
{
if (a==true)
{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * 2);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 2);
a=false;
}
else{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width *0.5);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 0.5);
a = false
}
private void button2_Click(object sender, EventArgs e)
{
if (a==true)
{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * 2);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 2);
a=false;
}
else{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width *0.5);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 0.5);
a = false
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void button2_Click(object sender, EventArgs e)
{
if (pictureBox1.Width >=50)
{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * 0.8);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 0.8);
}
else
{
MessageBox.Show(this, "图像已是最小,不能再缩小了!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void button3_Click(object sender, EventArgs e)
{
if (pictureBox1.Width < 310)
{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * 1.2);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 1.2);
}
else
{
MessageBox.Show(this, "图像已是最大,不能再放大了!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
{
if (pictureBox1.Width >=50)
{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * 0.8);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 0.8);
}
else
{
MessageBox.Show(this, "图像已是最小,不能再缩小了!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void button3_Click(object sender, EventArgs e)
{
if (pictureBox1.Width < 310)
{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * 1.2);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 1.2);
}
else
{
MessageBox.Show(this, "图像已是最大,不能再放大了!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
更多追问追答
追问
你的意思是两个按钮,一个变大一个变小。我是想点击一下图片放大 ,再点就变回原大小,要怎么写?
追答
boolean a=true;
private void button2_Click(object sender, EventArgs e)
{
if (a=true)
{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * 2);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 2);
a=false;
}
else{
pictureBox1.Width = Convert.ToInt32(pictureBox1.Width *0.5);
pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * 0.5);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |