Solved

How can i contorl the menu in vb.net

Posted on 2004-08-18
2
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Industry Leaders: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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