Solved

How can i contorl the menu in vb.net

Posted on 2004-08-18
2
208 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 85

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 125 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

14 Experts available now in Live!

Get 1:1 Help Now