This article describes the implementation of the page button timing hiding function in WinForm. Share it for your reference, as follows:
Sometimes when making a program, you need to display an item on the page, and then disappear after a period of time. At this time, it can be achieved through timer timing.
private void Form1_Load(object sender, EventArgs e) { t = new (3000); += new (OnTimedEvent); = true; = false; }
Then inOnTimedEvent
Write the corresponding code in the event, columns such as: = false;
At this time, we will find that these two are not the same thread, so we need to use a delegatedelegate
To implement cross-threading
Define a delegate
private delegate void SetVisibleCallback(); //Call the following method in the place where the value is assignedprivate void SetVisible() { // InvokeRequired needs to compare the calling thread ID and the creating thread ID // Return true if they are not the same if (this.) { SetVisibleCallback d = new SetVisibleCallback(SetPan); (d); } else { this. = false; } }
This is called in the event generated by the timerSetVisible()
Just
private void OnTimedEvent(object sender, e) { SetPan(); }
Of course, if you don't need to delegate implementation, you canOnTimedEvent
Write in events
CheckForIllegalCrossThreadCalls = false;///// Avoid cross-threading problems = false;
For more information about C# related content, please check out the topic of this site:Summary of WinForm control usage》、《Summary of C# form operation skills》、《C# data structure and algorithm tutorial》、《Tutorial on the usage of common C# controls》、《Introduction to C# object-oriented programming tutorial"and"Summary of thread usage techniques for C# programming》
I hope this article will be helpful to everyone's C# programming.