0

说我有这个:

Dim Editor As frmEditor
Editor.Text = "New Form"
Editor.Controls.Add(richTextBox)

然后稍后在子例程中,我这样做:

Editor = New frmEditor

是否可以保存先前声明的控件/数据以Editor供将来使用?声明的不是使用New关键字实例化的。

4

2 回答 2

1

[nkvu - 从评论转移到回答,以防有人有类似的查询......]

你能做类似的事情:

Dim oldEditor as frmEditor 

然后在你做之前:

Editor = New frmEditor 

做这个:

oldEditor = Editor

oldEditor然后应该有对前一个对象的引用

于 2013-03-27T22:08:08.570 回答
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
于 2013-03-27T22:22:49.807 回答