[英]How to make a picture that follow the mouse movement?
我正在用 C# 2.0 編寫一個窗口應用程序。
我已經添加了一張圖片作為項目的參考。
我不能做的是:
我需要鼠標移動后圖片移動,這意味着屏幕上鼠標的標志旁邊會有我的圖片隨它移動。
我想我應該使用MouseMove
的功能,但我看不出究竟是如何使用的。
任何幫助都會有用:) 謝謝!
為了將位圖保存到圖片框以便顯示,您可以簡單地設置如下:
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);
}
您必須處理MouseMove
事件並根據新的鼠標位置更改表單上的圖片位置。
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.pictureBox1.Location = new Point(e.X, e.Y);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.