C# 如何制作跟随鼠标移动的图片?

C# 如何制作跟随鼠标移动的图片?,c#,C#,我正在用C#2.0编写一个窗口应用程序。 我有一张我已经添加的图片作为项目的参考 我不能做的是: 我需要的图片移动后,鼠标移动,这意味着旁边的屏幕上的鼠标的标志将有我的图片与它一起移动 我想我应该使用MouseMove的功能,但我看不出具体的用法 任何帮助都是有用的:) 谢谢 您必须处理MouseMove事件,并根据新的鼠标位置更改窗体上的图片位置。您必须处理MouseMove事件,并根据新的鼠标位置更改窗体上的图片位置。为了将位图保存到图片框中以便显示,您可以简单地如下设置: private

我正在用C#2.0编写一个窗口应用程序。
我有一张我已经添加的图片作为项目的参考

我不能做的是:
我需要的图片移动后,鼠标移动,这意味着旁边的屏幕上的鼠标的标志将有我的图片与它一起移动

我想我应该使用
MouseMove
的功能,但我看不出具体的用法

任何帮助都是有用的:)
谢谢

您必须处理
MouseMove
事件,并根据新的鼠标位置更改窗体上的图片位置。

您必须处理
MouseMove
事件,并根据新的鼠标位置更改窗体上的图片位置。

为了将位图保存到图片框中以便显示,您可以简单地如下设置:

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
   this.pictureBox1.Location = new Point(e.X, e.Y);
}
this.pictureBox.Image = yourBitmapImage;
private void Form1_MouseMove(object sender, EventArgs e)
{
    var me = (MouseEventArgs)e;
    this.pictureBox1.Location = new Point(me.X, me.Y);
}
要设置
MouseMove
功能,请右键单击VisualStudios中的表单并转到属性。根据您的版本,您可能会在小窗口中看到闪电。然后,您可以定义或分配与Gabe所说类似的
MouseMove
函数

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    this.pictureBox1.Location = new Point(e.X, e.Y);
}
如果代码的参数为
EventArgs e
,则可以将其转换为
MouseEventArg
,如下所示:

this.pictureBox.Image = yourBitmapImage;
private void Form1_MouseMove(object sender, EventArgs e)
{
    var me = (MouseEventArgs)e;
    this.pictureBox1.Location = new Point(me.X, me.Y);
}

为了将位图保存到图片框中以便显示,您只需按如下方式进行设置:

this.pictureBox.Image = yourBitmapImage;
private void Form1_MouseMove(object sender, EventArgs e)
{
    var me = (MouseEventArgs)e;
    this.pictureBox1.Location = new Point(me.X, me.Y);
}
要设置
MouseMove
功能,请右键单击VisualStudios中的表单并转到属性。根据您的版本,您可能会在小窗口中看到闪电。然后,您可以定义或分配与Gabe所说类似的
MouseMove
函数

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    this.pictureBox1.Location = new Point(e.X, e.Y);
}
如果代码的参数为
EventArgs e
,则可以将其转换为
MouseEventArg
,如下所示:

this.pictureBox.Image = yourBitmapImage;
private void Form1_MouseMove(object sender, EventArgs e)
{
    var me = (MouseEventArgs)e;
    this.pictureBox1.Location = new Point(me.X, me.Y);
}

就像Yads问的,或者你是指屏幕上的任何地方——甚至在WinForms之外?在这种情况下,如果您在Windows上工作,如果您在使用MONO,则需要使用Win32 API。我不知道如何完成上述操作。我在使用winForms,并且我的图片将保存为位图格式。就像Yads所问的,或者您指的是屏幕上的任何位置,甚至在winForms之外?在这种情况下,如果您在Windows上工作,如果您在使用MONO,则需要使用Win32 API。我不知道如何完成上述操作。我在使用winForms,我的图片将保存为位图格式。我的图片是位图格式,有没有简单的方法将其转换,以便在程序中使用pictureBox作为图片?代码中的常规转换似乎不起作用…我的图片是位图格式的,有没有简单的方法可以转换它,以便我可以在程序中使用pictureBox作为我的图片?代码中的常规转换似乎不起作用…如何更改位图的位置?我必须使用这种格式,但我看不到位置…如何更改位图的位置?我必须使用这种格式,但我看不到位于某个位置的属性。。。