Solved

How can i contorl the menu in vb.net

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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