实例化类 [英] Instantiate Class
本文介绍了实例化类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好.
我有两个窗户. window1已经打开,我想使用window2作为window1的控件或功能.
但是,如果我将将Dim设置为新的Window1窗口"不起作用.
有人可以帮我吗?
示例:
Window1有一个TextBox和按钮
Good morning.
I''m have two windows. The window1 already open, and I want to use the window2 a control or function of window1.
But if I put "Dim as new Window1 Window" does not work.
Can someone help me?
Example:
Window1 have a TextBox and button
Partial Public Class Window1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim Win2 as new Window2
Win2.show
End Sub
End Class
Window2有一个按钮
Window2 have a Button
<pre lang="vb">
Partial Public Class Window2
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim Win1 as new Window1
Win1.TextBox1.IsEnable = False ''It does not work
End Sub
End Class
推荐答案
在第一个函数中,您实例化Window2,然后结束该子例程,以使该子例程在变量超出范围时消失.您可能需要Win2
变量作为Window1的属性,因此只要Window1确实存在,它就一直存在.
在第二个函数中,您将创建一个新的Window1类,并尝试修改属性,然后结束子例程,从而销毁该实例.第二个子例程需要访问在程序开始时创建的Window1对象.
花更多时间阅读有关类,对象和范围的信息.
In the first function you instantiate Window2 and then end the subroutine so it disappears as the variable goes out of scope. You probably need theWin2
variable to be a property of Window1 so it remains in existence as long as Window1 does.
In the second function you create a new Window1 class and try to modify a property, and then end the subroutine, thus destroying that instance. The second subroutine needs to access the Window1 object created at the start of the program.
Spend some more time reading up about classes, objects and scope.
这篇关于实例化类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文