What i want to do is that when i click buttonX4 i want the text to change from "Copy To Clipboard" to "Your Bio Has Been Copied" Then i want it to wait for 2 seconds then i want it to change back to "Copy To Clipboard". I did this with the assist of a timer. It all works until it goes to

public void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            buttonX4.Text = "Copy To Clipboard";

        }

after this this message comes up : "Cross-thread operation not valid: Control 'buttonX4' accessed from a thread other than the thread it was created on."
How can i fix it ?

MY CODE

public void buttonX4_Click(object sender, EventArgs e)
        {
            buttonX4.Text = "Your Bio Has Been Copied";
            timer1.Start();


        }
private void timer1_Tick(object sender, EventArgs e)
        {
            l_time = new System.Timers.Timer(2000);
            l_time.AutoReset = false;
            l_time.Start();
            l_time.Elapsed += new ElapsedEventHandler(OnTimedEvent);

        }


        public void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            buttonX4.Text = "Copy To Clipboard";

        }

Edited 6 Years Ago by trippinz: n/a

thanks, it works.

I made a mistake in the coding though. The coding works, i.e. halts on "your bio ..ted" for 2 secs, then changes to "copy to ..rd" but then when i click it again it doesnt halt/wait on "your bio ..ted" for 2 secs it just bypasses it (well it shows for a fraction of a second)

What do i do ?

This question has already been answered. Start a new discussion instead.