如何在winform中访问usercontrol上的用户控件和按钮? [英] How do I access user control and buttons on the usercontrol in winform?

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

问题描述

我有一个winform,在这种形式我调用用户控件如果我从winfrom点击按钮我怎样才能访问用户控件及其按钮的实例。以及我如何隐藏用户控制按钮



我尝试了什么:



我不知道我是如何解决这个问题的

I have a winform in that form i am calling user controls if i click button from winfrom how can i access the instance of user control and its button.and how i hide the user control button

What I have tried:

I have no idea how i solve this

推荐答案

如果我理解你的问题,你想从外面访问用户控件里面的控件。



如果这是我强烈建议不要这样做。如果需要从外部影响控制行为或从中读取信息,请在控件中定义属性和方法。如果您需要接收通知,请在用户控件中定义事件。



创建用户控件时的一个好原则是,从外部您不需要知道控件是什么实际上包含或如何工作。如上所述,你只需要有意义与之沟通。



看看例如创建Windows窗体用户控件 [ ^ ]。即使它是VB而且相当陈旧,它解释了第一步。
If I understand your question correctly, you want to access the controls inside a user control from outside.

If this is the case I would strongly advice not to do so. If you need to affect the control behaviour from outside or read information from it, define properties and methods in the control. If you need to receive notifications, define events in the user control.

One good principle when creating user controls is that from outside you should not need to know what the control actually contains or how it works. You just need to have meanings to communicate with it as described above.

Have a look at for example Creating a Windows Form User Control[^]. Even though it's VB and rather old it explains the first steps.


这篇关于如何在winform中访问usercontrol上的用户控件和按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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