Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SWITCH FORMS AT PANEL

Posted on 2011-03-19
9
Medium Priority
?
449 Views
Last Modified: 2012-06-27
Hi All,

I try to show forms at panel.

Here are the controls:

1. mdiform
2. pnlMenu as menu to select Menu use picturebox inside this panel.
3. pnlForm to show form inside it.

The problem is how to switch form among shown form at pnlForm when menu a pnlMenu is click ?

Is there any better idea to show forms inside a control for the same purpose ?

Thank you.
Private Sub Show_Bank()

        Dim frmBank As New frmBank

        frmBank.TopLevel = False
        Me.pnlForm.Controls.Add(frmBank)

        With frmBank
            .WindowState = FormWindowState.Maximized
            .Text = "SAMPLE FORM BANK"
            '.Dock = DockStyle.Fill
            .Show()
        End With

    End Sub

Open in new window

0
Comment
Question by:emi_sastra
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:Hawkvalley1
ID: 35174114
Maybe instead of a form you use a UserControl and add that to the panel. You can have all the same functionality.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35174118
Hi Hawkvalley1,

I don't get it.

Thank you.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35174200
Just clear the Panel before you add the new form...

    Me.pnlForm.Controls.Clear()
0
Independent Software Vendors: 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!

 
LVL 1

Author Comment

by:emi_sastra
ID: 35174211
Hi Idle_Mind,

Suppose there are 2 forms.

1. Cash
2. Bank

The Bank form is firstly Shown and user already input something but not saved yet.
Then user show form Cash.

Then use switch to form Bank, what will be happened to the data at form Bank that is in the middle of editing ?

Thank you.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35174220
If you need them to keep state then move their declarations out to the CLASS level:
Private frmBank As New frmBank ' <-- add it here instead

    Private Sub Show_Bank()
        ' Dim frmBank As New frmBank <-- get rid of this one

        Me.pnlForm.Controls.Clear()
        With frmBank
            .TopLevel = False
            .WindowState = FormWindowState.Maximized
            .Text = "SAMPLE FORM BANK"
            '.Dock = DockStyle.Fill
            .Show()
        End With
        Me.pnlForm.Controls.Add(frmBank)
    End Sub

Open in new window


...doing a similar thing with the Cash form.

Do the forms have BorderStyle set to None?  If not, and they have the 'X' on them still, then we need to add additional code.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35174226
Interesting, let me try first.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35174239
I've tried it.

There are several problems:

1. The form .WindowState = FormWindowState.Maximized is not work.
2. When I close a form and reopen it then rise error "Cannot access a disposed object. Object name: 'frmKas'."

Thank you.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35175342
Follow this pattern for all of the Forms that need to appear in your Panel:
Public Class Form1

    Private WithEvents frmBank As frmBank = Nothing
    Private WithEvents frmCash As frmCash = Nothing

    Private Sub Show_Bank()
        If IsNothing(Me.frmBank) Then
            Me.frmBank = New frmBank
            Me.frmBank.TopLevel = False
            Me.frmBank.Text = "SAMPLE FORM BANK"
            Me.pnlForm.Controls.Add(Me.frmBank)
        End If

        Me.frmBank.WindowState = FormWindowState.Maximized
        Me.frmBank.Show()
        Me.frmBank.BringToFront()
    End Sub

    Private Sub frmBank_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles frmBank.FormClosed
        Me.frmBank = Nothing
    End Sub

    Private Sub Show_Cash()
        If IsNothing(Me.frmCash) Then
            Me.frmCash = New frmCash
            Me.frmCash.TopLevel = False
            Me.frmCash.Text = "SAMPLE FORM CASH"
            Me.pnlForm.Controls.Add(Me.frmCash)
        End If

        Me.frmCash.WindowState = FormWindowState.Maximized
        Me.frmCash.Show()
        Me.frmCash.BringToFront()
    End Sub

    Private Sub frmCash_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles frmCash.FormClosed
        Me.frmCash = Nothing
    End Sub

End Class

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35177412
Hi Idle_Mind,

It works great.

Just a small change from

Me.pnlForm.Controls.Add(Me.frmCash)
to
frmCash.Parent = pnlForm

Thank you very much for your help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

971 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