在VS中,picturebox里的图片在鼠标移过的时候改变成另一张图片,这样的代码怎么写呢?
3个回答
展开全部
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
pictureBox1.ImageLocation = "移过时要显示的图像文件的路径";
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
pictureBox1.ImageLocation = "原来图像文件的路径";
}
{
pictureBox1.ImageLocation = "移过时要显示的图像文件的路径";
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
pictureBox1.ImageLocation = "原来图像文件的路径";
}
追问
出错了,说没有ImageLocation的定义。怎么办呢?
追答
你检查一下图像文件的路径有没有写错,例如·pictureBox1.ImageLocation = @"D:\我的文档\My Pictures\10.gif";
展开全部
//获得当前项目运行的路径,image文件夹应该放在Debug这个文件夹中
path = System.IO.Directory.GetCurrentDirectory();
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
this.pictureBox1.Image=System.Drawing.Image.FromFile(path + @"\images\CloseButton_Hover.bmp");
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.Image = System.Drawing.Image.FromFile(path + @"\images\CloseButton_Down.bmp");
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pictureBox1.Image = System.Drawing.Image.FromFile(path + @"\images\CloseButton_Normal.bmp");
}
path = System.IO.Directory.GetCurrentDirectory();
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
this.pictureBox1.Image=System.Drawing.Image.FromFile(path + @"\images\CloseButton_Hover.bmp");
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.Image = System.Drawing.Image.FromFile(path + @"\images\CloseButton_Down.bmp");
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pictureBox1.Image = System.Drawing.Image.FromFile(path + @"\images\CloseButton_Normal.bmp");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哪就查看api有没有鼠标事件这样函数!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询