我的代码用于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;
}
其他表格不会回答
如果form2已打开。上面的代码不起作用。
答案 0 :(得分:0)
嗯,我不确定究竟要完成什么,但尝试设置form2.Owner = this
(如果你从from1显示form2)或form2.Owner = form1。
答案 1 :(得分:0)
屏幕保护程序的代码:
// 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);
}
}
任何形式都应该使用Timer Component
这不是解决这个问题的方法吗?
屏幕保护程序可以使用Windows吗?