Vegetable Chicken Learning Notes Asynchronous invocation of the--winform control

Source: Internet
Author: User

In a WinForm project, it is difficult to use the window control directly except for classes other than the window class, because the control object is not static (static), but it cannot go to the designer to modify the properties of the space. There is also a case where the value of the control needs to be changed automatically. You need to use the event in this case


Arbitrarily declare a delegate at the appropriate location in the project, the parameter type is consistent with the control

 Public Delegate void Testdelegate (string msg);

Declare the event, and define the event accessor:

 Public Event testdelegate testevent{{    add    {        + = value;    }    Remove    {        = value;    }}

Methods for calling an event-bound control asynchronously:

TestEvent + = Txtmethod;  Public void Txtmethod (string msg)// The specific method of the asynchronous invocation of the control     {delegate(  String  m)    {        + = m;    }    Txtcontent.invoke (Del, msg);}

This TXT control can output the value of MSG when the event testevent is triggered:

string " This is a Test " ; if null) // Triggering events    TestEvent (msg);

The first time you study, you have to practise more.

Yes, that's what you learned from Zhang Ziyang's network programming article:

Vegetable Chicken Learning Notes Asynchronous invocation of the--winform control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.