如果继承usercontrole如何从另一个类调用类 [英] if inherits usercontrole how to call class from some another class
本文介绍了如果继承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
不能显示它.它是一个控件(如Button
或TextBox
或其他任何控件),您可以将其放入Form
中.
如果要将控件放在表单中,然后使用ShowDialog
显示该表单,则不需要UserControl
.只需在项目中添加Form
并将控件放入其中即可.
I think you are confused aboutUserControl
...
AUserControl
is not aForm
. It can''t be displayed withShowDialog
. It is a control (like aButton
orTextBox
or whatever) which you can put inside aForm
.
If you want to put controls inside a form and then display that form usingShowDialog
, then you don''t need aUserControl
. Just add aForm
in your project and put the controls inside it.
这篇关于如果继承usercontrole如何从另一个类调用类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文