سؤال

Say I have this:

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

Then later in a sub routine, I do this:

Editor = New frmEditor

Is it possible to save the controls/data of the previously declared Editor for future use? The one which was declared not the one which was instantiated using the New keyword.

هل كانت مفيدة؟

المحلول

[nkvu - moved from comments to answer in case anyone has a similar query....]

Could you do something like:

Dim oldEditor as frmEditor 

Then before you do:

Editor = New frmEditor 

Do this:

oldEditor = Editor

oldEditor should then have a reference to the previous object

نصائح أخرى

Dim Editor As frmEditor

... does not create an editor, it declares only an empty variable, therefore ...

Dim Editor As frmEditor
Editor.Text = "New Form"

... will fail!

You must create a form with New:

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

Or

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

To answer your question:

Assign the "old" editor to another variable

Dim oldEditor As Editor = frmEditor
frmEditor = New frmEditor()
frmEditor.RtfText = oldEditor.RtfText

Also make a public property that allows you to access what you need to access from outside of the form

Public Property RtfText() As String
    Get
        Return richTextBox.Rtf
    End Get
    Set(ByVal value As String)
        richTextBox.Rtf = value
    End Set
End Property
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top