?
Solved

How can i contorl the menu in vb.net

Posted on 2004-08-18
2
Medium Priority
?
223 Views
Last Modified: 2010-04-23
Hei

I can't handle da menu in da way dat if once the menu is been clicked the form will appear and  other time if da same menu is been clicked it shouldn't appear again dat same form or in other words shouldn't make n new instance ..

one way was of disabling n other of making it visible = false ... but ain't working ...
0
Comment
Question by:cee1891
2 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11836107
Here is a simple example of a Button on Form1 that makes only one instance of Form2 appear.  If Form2 is minimized then it is restored.

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents f2 As Form2

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

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

End Class
0
 
LVL 8

Accepted Solution

by:
wguerram earned 500 total points
ID: 11836608


Private Sub Showform2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Showform2ToolStripMenuItem.Click
       'If this form type is loaded, a reference to that form is returned
        Dim form As Object = FormLoaded(Form2.GetType)

        'If the form is not loaded, the create new instance
        If IsNothing(form) Then
            form = New Form2
            form.MdiParent = Me
            form.Show()
        Else
            form.Visible = True
            form.Activate() 'Just activate it
        End If
    End Sub

   'Look for the form type
    Private Function FormLoaded(ByVal FormType As Type) As Object
        Dim i As Integer
        Dim _form As Object

        For i = 0 To Me.MdiChildren.Length - 1
            'compare types
            If Me.MdiChildren(i).GetType.ToString = FormType.ToString Then
                _form = Me.MdiChildren(i)
                Exit For
            End If
        Next

        Return _form
    End Function
0

Featured Post

Technology Partners: 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!

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 …
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 …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

839 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