. Net event in the class, why can it be defined as static? However, the delegate type is not allowed.

Source: Internet
Author: User

I have a form and a clsevent class,
An event is registered in the form.
A delegate + event is defined in the clsevent class, and an event is thrown. But why cannot I obtain this event in the form ??

 

Later, I modified the event defined in the clsevent class to static, and the form can be obtained?

Clsevent class public class clsevent {Public Delegate void showsometing1 (string strtxtbox); public static event showsometing1 btnclick1; private string _ strcontent; Public String strcontent {get {return _ strcontent ;} set {// when the attribute is changed, the event _ strcontent = value is triggered; // The event is triggered in the event issuer. If (btnclick1! = NULL) {btnclick1 (_ strcontent );}}}

 

 Form1_Load
clsEvent m_clsEvent = new clsEvent();
// Form registers the event m_clsevent. btnclick1 + = new m_clsevent. showsometing1 (textboxchange) to the class)
Private void button#click (Object sender, eventargs e) {// modify attributes to stimulate events. M_clsevent. strcontent = This. textbox1.text;} public void textboxchange (string strcontent) {this.txt class. Text = strcontent ;}

 

 

Related Article

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: info-contact@alibabacloud.com 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.