Shake detection mouse
My code is used to form1
private int X,Y;
private void timer1_Tick(object sender, EventArgs e)
{
if (this.X != Cursor.Position.X ||
this.Y != Cursor.Position.Y)
{
this.Form1_Load(this, e);
}
else
{
this.Text = (Convert.ToInt16(this.Text)+1).ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "0";
this.X = Cursor.Position.X;
this.Y = Cursor.Position.Y;
}
开发者_如何转开发
Other forms will not answer
If the form2 is open. The above code does not work.
Well I am not sure what exactly want to accomplish, but try to set form2.Owner = this
(if you show form2 from from1) or form2.Owner = form1.
This code for the screensaver :
//inForm1
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
private static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
//...
private const int SC_SCREENSAVE = 0xF140;
private const int WM_SYSCOMMAND = 0x0112;
//...
public static void SetScreenSaverRunning()
{
SendMessage
(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
}
public void Shakedetectionmouse(EventArgs e)
{
//CallTimer1_Tick
timer1_Tick(this,e);
}
private void timer1_Tick(object sender, EventArgs e)
{
//ShowScreenSaver
timer1.Enabled = true;
timer1.Interval = 1000;
SetScreenSaverRunning();
}
private void button1_Click(object sender, EventArgs e)
{
//ShowForm2
using (var Form2 = new Form2())
{
Form2.ShowDialog();
}
}
//Inform2
private void Form2_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 2000;
}
private void timer1_Tick(object sender, EventArgs e)
{
using(var form1 = new Form1())
{
form1.Shakedetectionmouse(EventArgs.Empty);
}
}
In any form should be used Timer Component
Is it not a way to solve this issue?
screen saver Windows can be used?
精彩评论