开发者

.NET (C#) passing messages from a custom control to main application

开发者 https://www.devze.com 2022-12-27 02:27 出处:网络
A custom windows form control named \'tweet\' is in a dll. The custom control has couple of basic controls to display a tweet. I add this custom control to my main applicat开发者_运维问答ion. This cus

A custom windows form control named 'tweet' is in a dll. The custom control has couple of basic controls to display a tweet. I add this custom control to my main applicat开发者_运维问答ion. This custom control has a button named "retweet", when some user clicks this "retweet" button, i need to send some message to the main application. Unfortunately the this tweet control has no idea about this main application (both or in their own namespaces)

How can i send messages from this custom control to the main application?


One way is to add an event to your control and have the control fire that event when it needs to send a message. The main form can add an event handler when it creates the form and be notified of the messages. This way your control does not need to have any hard-coded reference to the main form.


You raise and handle the event. See the code sample on this page (you might have to choose the language on the page to be C#)

http://msdn.microsoft.com/en-us/library/9aackb16(v=VS.71).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号