Form transparency from static void C#

Basically, I have a timer that once reaches 5000ms will set the opacity of my main form to 0.5 The problem is that I can't change the opacity of my form from a static void... Here is my code, any sugestions? :

public partial class Form1 : Form
{

    public Form1()
    {
        myTimer.Tick += new EventHandler(TimerEventProcessor);
        // Sets the timer interval to 5 seconds.
        myTimer.Interval = 5000;
        myTimer.Start();
    }

    public static void TimerEventProcessor(Object myObject,
                                        EventArgs myEventArgs)
    {
        myTimer.Stop();
        //Set Opacity here

    }


}
Jon Skeet
people
quotationmark

Well your static method doesn't have an instance of the form to work with.

The simplest approach is just to stop it from being a static method. There's no obvious reason why you'd want it to be a static method anyway - or why you'd want myTimer to be static, which I assume it is, based on the usage.

Once you've made it an instance method, you can just change the opacity as you normally would, assuming that the Timer in question is a System.Windows.Forms.Timer (so it'll be ticking on the right thread...)

people

See more on this question at Stackoverflow