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
Solved

How can i contorl the menu in vb.net

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pagebreak issue while printing the aspx page 3 34
VB.NET - Error - Object not set in Module 4 39
VB.net Open Folder in Windows Explorer 3 50
Open a link in vb.net 2 15
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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 …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

790 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