如何在用户控件上处理Button Click事件? [英] How to Handle Button Click event on user Control ?

查看:92
本文介绍了如何在用户控件上处理Button Click事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在C#.net中创建了一个用户控件,其中包含6个按钮。

我使用了那个控件在Windows窗体中,我想在Windows窗体中单击按钮事件。

Hello everyone,

I created one user control in C#.net, which contains 6 Buttons.
And I used that control in Windows Form , and I want Click event of Button in Windows Form.

推荐答案

你没有。

相反,你创建一个作为UserControl的一部分的事件,当按钮Click发生时控件引发,外部世界处理它。



这样,外面的世界不需要了解控制内部的任何信息,控制可以自由改变其工作方式而不影响外部世界。



事件很容易创建:添加活动的简单代码片段 [ ^ ]显示如何使它更容易!
You don't.
Instead, you create an event as part of your UserControl which the control raises when the button Click happens, and the outside world handles that.

That way, the outside world doesn't need to know anything about the controls internals, and the control is free to change the way it works without affecting the outside world.

Events are easy to create: A Simple Code Snippet to Add an Event[^] shows how to make it even easier!

这篇关于如何在用户控件上处理Button Click事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆