Duplicate A Form Object - Please Help

G

Guest

I am new to the .Net environment, so please bear with me.

I am passing a form object (e.g. formA) to an existing form (e.g. formB) by setting a property value defined in formB to hold the formA object. Please keep in mind that formB is defined in a separate library project.

I then display formB. Once formB is displayed, I have code in a double click event procedure in formB to display formA by getting the form object throught the property definition described above.

The code works perfectly fine initially displaying formA; however if formA is closed, I cannot redisplay it from the double click event procedure. I guess that by closing formA, I'm apparently destroying the object that I'm getting from the formB's property value. I presume that the object being set in the property value is a reference to when formA was originally instanciated and not a copy of formA.

Is there a way of making a copy of formA from within formB? Or is there a way re-instanciating formA from within formB? Please keep in mind that formB is in a separate library project and as such doesn't know about the formA type. As such I can't simply say:

Dim formA as New formB.

Any help would be incredibly appreciated.

Thanks
Ned
 
I

Imran Koradia

This is what I think - if you close down the form, you still have a
reference to the form object. you simply need to call the Show() of the form
once again and you should be able to display the form however many times you
want to. I dont think you should need to make a copy of FormA - that would
be a waste. I'm not sure what code you have in your double click event which
would cause it to load the first time fine and not after that. Are you
setting the reference of FormA to nothing after you're done with form? That
could be problem. It'll be easier if you post your code how you are getting
the reference to FormA in the first place (your property) and code in your
double click event.
Imran.

BakelNB said:
I am new to the .Net environment, so please bear with me.

I am passing a form object (e.g. formA) to an existing form (e.g. formB)
by setting a property value defined in formB to hold the formA object.
Please keep in mind that formB is defined in a separate library project.
I then display formB. Once formB is displayed, I have code in a double
click event procedure in formB to display formA by getting the form object
throught the property definition described above.
The code works perfectly fine initially displaying formA; however if formA
is closed, I cannot redisplay it from the double click event procedure. I
guess that by closing formA, I'm apparently destroying the object that I'm
getting from the formB's property value. I presume that the object being set
in the property value is a reference to when formA was originally
instanciated and not a copy of formA.
Is there a way of making a copy of formA from within formB? Or is there a
way re-instanciating formA from within formB? Please keep in mind that formB
is in a separate library project and as such doesn't know about the formA
type. As such I can't simply say:
 
G

Guest

Hey Imran,
I appreciate your reply. I’m actually using the show method to display FormA. The first time the code in the double click event executes, FormA displays perfectly and the code in FormA’s load event exeutes. Once FormA is displayed and assuming it’s not closed executing the show method to display FormA appears to do nothing which is what is expected because FormA is already displayed. What I want to do is close the form if it’s already displayed and show it again so the code in the form’s load event gets executed. That’s when I started to have understand the original problem described in my post. That is once I close the form, I can’t display it again.

I think the problem has to do with the “Type†that I’m defining the form has. I’m using the generic type “Form†to pass in the original form reference as opposed to using the specific form’s form type. I’m doing this because I want to be able to pass in different forms that will get displayed.

I’ve included the code in my double click event. I appreciate you looking into this.

Private Sub lstView_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstView.DoubleClick
'*****************************************************
' Display the Deal details form
'******************************************************
Dim item As ListViewItem
Dim subitem As ListViewItem.ListViewSubItem
Dim frm As Form 'Form object

'******************************************************
' Display the form object that was passed to the Deal Selector
'******************************************************
Me.DealId() = Me.lstView.SelectedItems(0).SubItems(2).Text 'Set the deal selector's dealid property
frm = Me.FormToDisplay 'Get the form from the property to display
frm.MdiParent = Me.ParentForm() 'Set the form's parent property to the current parent
frm.Show() 'Display the form



I've also tried diming the "frm" object as New Form. That doesn't work either. Any assistance would be incredibly appreciated.

Thanks
Ned
 
C

Chris Dunaway

On Thu, 1 Jul 2004 05:30:01 -0700, NeddyRock wrote:

Don't *close* the form, *hide* it. If you need to call the code in the
load event, place that code in a separate sub so you can call it again.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top