Solved

vb.net Mdi Forms

Posted on 2007-03-25
7
386 Views
Last Modified: 2012-06-21
I have 2 forms - 1 mdiparent and other one mdichild
i open mdi child forms with the click event of a button in mdi parent
the coding which i am using to open mdichild is
in General delaration part
dim childform as form2
in button click
childform=new form2
childform.mdiparent=me
childform.bringtofront
childform.show()

My question is when the child form opens i am still able to see the button in form1 that is mdi parent
is there any solution for this the form1 button shouldnt be seen and i can open child form only through
button
0
Comment
Question by:pearlym
  • 2
7 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
see my article http://www.emoreau.com/Entries/Articles/2003/09/Fun-with-MDI-forms.aspx in which you will find a method IsChildInMemory that will help you finding if the form is already visible or not (instead of hiding the button, you can prevent the form from appearing twice)..
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
You can also declare your childform as WithEvents and reset your variable when the form closes:

Public Class MdiParent

    Private WithEvents childForm As Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If childForm Is Nothing Then
            childForm = New Form2
            childForm.MdiParent = Me
        End If
        If childForm.WindowState = FormWindowState.Minimized Then
            childForm.WindowState = FormWindowState.Normal
        End If
        childForm.Show()
    End Sub

    Private Sub childForm_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles childForm.Closed
        childForm = Nothing
    End Sub

End Class
0
 

Author Comment

by:pearlym
Comment Utility
Still the parent form button is visible even when the child form is active
I tried all the methods
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
Comment Utility
So you just want the Button invisible while the form is active?

How about?...

Public Class MdiParent

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Visible = False
        Dim cf As New Form2
        cf.MdiParent = Me
        AddHandler cf.Closed, AddressOf cf_Closed
        cf.Show()
    End Sub

    Private Sub cf_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
        Button1.Visible = True
    End Sub

End Class
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

8 Experts available now in Live!

Get 1:1 Help Now