Make forms invisible

I have a VB.NET application with a MDI enabled form containing several child forms. At any time several of the child forms may be open with data that must be saved before the forms are closed and set to Nothing.

My question is:
Is it possible to temporally make some of the child forms invisible to the user without losing those forms data or having to save to avoid losing data. When the forms are brought back they and it's data must be in the same state as when they become invisible.

By invisible I mean that the forms can not be seen (unreachable) by the user and can not be brought back by just pressing the min/max buttons up right in the MDI container. The code to set forms (in)visible must be located in it’s own sub.
daghoffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

elimesikaCommented:
There is a trick to do that by moving the form to unreachable position.

See sample code at
http://www.justvb.net/tips/Forms/Forms_MDI_-_Hiding_MDI_Child_Forms_at_Run_Time.html
0
daghoffAuthor Commented:
Nice, but it looks a bit dirty. Can I be certain it will be supported in future versions of .NET?

Is there no better way?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
?...

Why not just set the Visible() property of your MdiChildren to True/False?  
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2
        f2.MdiParent = Me
        f2.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ChangeVisibility(False)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ChangeVisibility(True)
    End Sub

    Private Sub ChangeVisibility(ByVal VisibleState As Boolean)
        For Each frm As Form In Me.MdiChildren
            frm.Visible = VisibleState
        Next

        ' if you only want certain kinds, then do something like:
        For Each frm As Form In Me.MdiChildren
            If TypeOf frm Is Form2 Then
                frm.Visible = VisibleState
            End If
        Next
    End Sub

End Class

Open in new window

Idle-Mind-512471.flv
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

durgalakshmieCommented:
You can try minimizing the Form temporarily, once the control moves out of the Form
0
CodeCruiserCommented:
IM has nailed it. You can also use the Hide() method to hide the form and Show() method to show it again :-)

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
I'm guessing VB6 couldn't do this?...I can't remember.
0
VipulKadiaCommented:
try this : Yourform.Hide
0
daghoffAuthor Commented:
My problem is that I keep forgetting that forms are just another control.

I have now implemented a MDI test app with a lot of child forms. I have two groups of child forms and a button that sets one group invisible and the other visible.

The problem now is that during the switch the child forms flicker alott. I have tried SuspendLayout and ResumeLayout on the MDI, hoping it would control the flickering of the children, but with no luck.

Can this be solved?

0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use SendMessage() and WM_SETREDRAW on the MdiClient of your MdiParent form.

Here's a simplified example:
Public Class Form1

    Private MyMdiClient As MdiClient = Nothing

    Private State As Boolean = False
    Private Group1 As New List(Of Form)
    Private Group2 As New List(Of Form)

    Private Const WM_SETREDRAW As Integer = &HB

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal handle As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is MdiClient Then
                MyMdiClient = ctl
                Exit For
            End If
        Next

        For i As Integer = 1 To 20
            Dim frm As New Form
            frm.MdiParent = Me
            frm.Text = If(i Mod 2, "Group1", "Group2")
            If i Mod 2 Then
                Group1.Add(frm)
            Else
                Group2.Add(frm)
            End If
            frm.Show()
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SendMessage(MyMdiClient.Handle, WM_SETREDRAW, False, 0) ' Turn OFF MdiClient Updates

        ' Toggle the state of your MdiChildren somehow:
        State = Not State
        For Each frm As Form In Group1
            frm.Visible = State
        Next
        For Each frm As Form In Group2
            frm.Visible = Not State
        Next

        SendMessage(MyMdiClient.Handle, WM_SETREDRAW, True, 0) ' Turn ON MdiClient Updates
        MyMdiClient.Refresh()
    End Sub

End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.