I'm writing a window application in C# 2.0.
I have a picture that I already added as a reference for the project.
The thing I can't do is this:
I need the picture to move after the mouse movement,it means that next to the mouse's sign on the screen there will be my picture to move with it.
I suppose that I should use the function of MouseMove
, but I can't see exactly how.
Any help would be useful :) ThanKs!
In order to save the Bitmap to a picture box so it is displayed, you could simply set it as follows:
this.pictureBox.Image = yourBitmapImage;
To set the MouseMove
function, right click on the form in VisualStudios and go to properties. Depending on your version, you might see a lightning bolt in the little window. Then you can define or assign the MouseMove
function similar to what Gabe said.
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.pictureBox1.Location = new Point(e.X, e.Y);
}
If you have code with the argument as an EventArgs e
, you can cast it as a MouseEventArg
as follows:
private void Form1_MouseMove(object sender, EventArgs e)
{
var me = (MouseEventArgs)e;
this.pictureBox1.Location = new Point(me.X, me.Y);
}
您必须处理MouseMove
事件并根据新的鼠标位置更改表单上的图片位置。
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.pictureBox1.Location = new Point(e.X, e.Y);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.