tags:

views:

56

answers:

2

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.

A: 

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.

ikirachen
A: 

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?

ehsan_d18
@ehsan: Edit your question with these details; don't create an answer unless you're answering your question.
Michael Petrotta
I found the answer
ehsan_d18