如果继承usercontrole如何从另一个类调用类 [英] if inherits usercontrole how to call class from some another class

查看:87
本文介绍了如果继承usercontrole如何从另一个类调用类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果它是由System.Windows.Forms.UserControl继承的,我如何在窗体应用程序中调用另一个类.我知道我们不能通过使用instance.showDilog()方法来调用它,然后如何调用此类CS文件.

how i can call an another class in form application if it is inherited by System.Windows.Forms.UserControl.I know we cant call it by using instance.showDilog() method then how to call such a cs files.thanks

推荐答案

您对待所有控件的方式相同.
因此,您可以将其从工具箱拖动到窗体上,或者将其添加到另一个控件的Controls集合中.
You treat it the same way as you treat all controls.
So you either drag it onto a form from your toolbox, or you add it to the Controls collection of another Control.
MyControl myControl = new MyControl
Form1.Controls.Add(myControl)


我认为您对UserControl ...
感到困惑
UserControl不是Form. ShowDialog不能显示它.它是一个控件(如ButtonTextBox或其他任何控件),您可以将其放入Form中.

如果要将控件放在表单中,然后使用ShowDialog显示该表单,则不需要UserControl.只需在项目中添加Form并将控件放入其中即可.
I think you are confused about UserControl...

A UserControl is not a Form. It can''t be displayed with ShowDialog. It is a control (like a Button or TextBox or whatever) which you can put inside a Form.

If you want to put controls inside a form and then display that form using ShowDialog, then you don''t need a UserControl. Just add a Form in your project and put the controls inside it.


这篇关于如果继承usercontrole如何从另一个类调用类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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