我正在用C# 2.0编写一个窗口应用程序。
我有一张图片,我已经添加了作为项目的参考。
我不能做的事情是:
我需要图片在鼠标移动后移动,这意味着屏幕上鼠标标志的旁边将有我的图片随其移动。
我想我应该使用MouseMove的函数,但是我不知道具体是怎么做的。
任何帮助都是有用的:)谢谢!
发布于 2015-11-24 13:30:59
为了将位图保存到图片框中以便显示,您只需按如下方式进行设置:
this.pictureBox.Image = yourBitmapImage;要设置MouseMove函数,请右键单击VisualStudios中的表单,然后转到属性。根据您的版本,您可能会在小窗口中看到闪电。然后,您可以定义或分配与Gabe所说的类似的MouseMove函数。
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.pictureBox1.Location = new Point(e.X, e.Y);
}如果您的代码将参数作为EventArgs e,则可以将其转换为MouseEventArg,如下所示:
private void Form1_MouseMove(object sender, EventArgs e)
{
var me = (MouseEventArgs)e;
this.pictureBox1.Location = new Point(me.X, me.Y);
}发布于 2011-01-21 05:23:22
您必须处理MouseMove事件,并根据新的鼠标位置更改窗体上的图片位置。
发布于 2011-01-21 05:26:31
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.pictureBox1.Location = new Point(e.X, e.Y);
}https://stackoverflow.com/questions/4752685
复制相似问题