Solved

SWITCH FORMS AT PANEL

Posted on 2011-03-19
9
434 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
Comment Utility
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
Comment Utility
Hi Hawkvalley1,

I don't get it.

Thank you.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Just clear the Panel before you add the new form...

    Me.pnlForm.Controls.Clear()
0
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
Interesting, let me try first.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now