Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SWITCH FORMS AT PANEL

Posted on 2011-03-19
9
Medium Priority
?
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

670 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