私はC#WinFormsアプリケーションを作成しています。フォームのMouseMoveイベントとMouseClickイベントは何らかの理由で起動されません。 (私はおそらく理由を知るとばかげていると感じるでしょう) 透明なフォーム(TransparencyKeyは背景色に設定されています)で、半透明のアニメーションGIFがピクチャボックスにあります。私はスクリーンセーバーを作っています。 提案がありますか?マウスイベントが発生しない
EDIT: MainScreensaver.cs
Random randGen = new Random();
public MainScreensaver(Rectangle bounds)
{
InitializeComponent();
this.Bounds = Bounds;
}
private void timer1_Tick(object sender, EventArgs e)
{
Rectangle screen = Screen.PrimaryScreen.Bounds;
Point position = new Point(randGen.Next(0,screen.Width-this.Width)+screen.Left,randGen.Next(0,screen.Height-this.Height)+screen.Top);
this.Location = position;
}
private void MainScreensaver_Load(object sender, EventArgs e)
{
Cursor.Hide();
TopMost = true;
}
private Point mouseLocation;
private void MainScreensaver_MouseMove(object sender, MouseEventArgs e)
{
if (!mouseLocation.IsEmpty)
{
// Terminate if mouse is moved a significant distance
if (Math.Abs(mouseLocation.X - e.X) > 5 ||
Math.Abs(mouseLocation.Y - e.Y) > 5)
Application.Exit();
}
// Update current mouse location
mouseLocation = e.Location;
}
private void MainScreensaver_KeyPress(object sender, KeyPressEventArgs e)
{
Application.Exit();
}
private void MainScreensaver_Deactive(object sender, EventArgs e)
{
Application.Exit();
}
private void MainScreensaver_MouseClick(object sender, MouseEventArgs e)
{
Application.Exit();
}
MainScreensaver.Designer.cs InitialiseComponentからの抜粋()
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.MainScreensaver_MouseClick);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainScreensaver_MouseMove);
コードを入力してください。 – anonymous
デザイナに移動し、[プロパティ]パネルを使用してイベントハンドラを削除します。その後、イベントハンドラを再追加します。 VS2010はWinFormsで面白いゲームをいくつか演奏し、ハンドラを読むことで問題を解決できます。また、カーソルを非表示にしても、クリックイベントが「非表示」にならないようにしてください。 – MoonKnight
@Killercam No luck :( –