?
Solved

Create a new instant of a form from a parameter passed to a sub

Posted on 2009-02-18
2
Medium Priority
?
141 Views
Last Modified: 2012-05-06
Hi Experts,
I have some code that opens a form inside a panel control. It worked fine to open one form. I would like to reuse the code to open a different form in the panel. I tried to pass the form as a parameter with no luck.
Thank You
John
Public Class frmTakeOff
Dim SubFrmTakeOffSubWalls As form
 
 Private Sub OpenTakeOffSubForm(ByVal SubFormName As Form, ByVal Edited As Boolean)
 
SubFrmTakeOffSubWalls = CType(Activator.CreateInstance(SubFormName.GetType()), Form)
        With SubFrmTakeOffSubWalls
 
            .TopLevel = False
            .Dock = DockStyle.Fill
            .Anchor = AnchorStyles.Bottom
            .WindowState = FormWindowState.Maximized
            If Edited = True Then
                .SubWallEditMode = True
                .CurrentTakeOffItemId = Me.TakeOffGridView.GetFocusedRowCellValue("TakeOffItemId")
            End If
 
            Me.Panel1.Controls.Add(SubFrmTakeOffSubWalls)
            AddHandler .UpdateTakeOffGrid, AddressOf FillTakeOffGrid
 
            .Show()
            Me.ToolStrip1.BringToFront()
        End With
 
    End Sub

Open in new window

0
Comment
Question by:DjJohnny
2 Comments
 
LVL 9

Accepted Solution

by:
Hawkvalley1 earned 2000 total points
ID: 23670431
It might have been easier to have 2 userControls that are built to your specs, then just, .remove(the old one) then .add(the new one). It also sounds like you are changing a value that causes your program to remove the current object and then add the same object only modified. Forms use the .show and controls use .add and you have both which may be the problem. What is the purpose for the new form?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23671271
You have declared your variable (being used in the "with" statement) as a generic Form:

    Dim SubFrmTakeOffSubWalls As form

Thus it has no idea what these properties are:

    .SubWallEditMode
    .CurrentTakeOffItemId

Or what this event is:

    .UpdateTakeOffGrid

If you have multiple form types that ALL have these Properties/Events, then make an INTERFACE that all of these Forms Implement and declare your "With" variable as that type instead:

    Dim SubFrmTakeOffSubWalls As YourInterfaceHere
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question