说我有这个:
Dim Editor As frmEditor
Editor.Text = "New Form"
Editor.Controls.Add(richTextBox)
然后在子例程中,我这样做:
Editor = New frmEditor
是否可以保存先前声明的Editor
的控件/数据以备将来使用?声明的那个不是使用New
关键字实例化的那个。
答案 0 :(得分:1)
[nkvu - 如果有人有类似的查询,请从评论转移到答案....]
你可以这样做:
Dim oldEditor as frmEditor
然后在你做之前:
Editor = New frmEditor
这样做:
oldEditor = Editor
然后 oldEditor
应该引用前一个对象
答案 1 :(得分:1)
Dim Editor As frmEditor
...不创建编辑器,它只声明一个空变量,因此......
Dim Editor As frmEditor
Editor.Text = "New Form"
......会失败!
您必须使用New
创建表单:
Dim Editor As frmEditor
Editor = New frmEditor()
Editor.Text = "New Form"
或者
Dim Editor As frmEditor = New frmEditor()
Editor.Text = "New Form"
回答你的问题:
将“旧”编辑器分配给另一个变量
Dim oldEditor As Editor = frmEditor
frmEditor = New frmEditor()
frmEditor.RtfText = oldEditor.RtfText
还创建一个公共属性,允许您从表单外部访问您需要访问的内容
Public Property RtfText() As String
Get
Return richTextBox.Rtf
End Get
Set(ByVal value As String)
richTextBox.Rtf = value
End Set
End Property