Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm rather new to VB and programming in general, and I could use a little guidance. I was able to build my application the way I want it but I just need one more piece.

Is there a way to launch a particular form in my project from a desktop shortcut?
There are 5 forms in the tray application, and I would like to be able to launch one in particular from a desktop shortcut.
Is that possible? If so, where would I start?

Thanks in advance!

What I have tried:

I have not been able to find anything specific to my question, and that could be due to incorrect phrasing...

I found some code (On CodeProject I believe) as seen below. It is a form-less tray application which is what I think I wanted. As for the Timer, I wasn't sure I needed that and it works fine without it.?.?
Here is the module code I am using. How would I fit this answer into my code? [Remember... I'm a NOOB! (as much as I hate to admit it)]

VB
<pre>Imports Microsoft.Win32

Module Module1
    Private MyNotifyIcon As NotifyIcon          'ICON IN SYSTEM TRAY COMPONENT
    Private MyContextMenu As ContextMenu        'CONTEXT MENU WHEN ITEM IS CLICKED ON
    'Private MyTimer As Timer
    Private WithEvents Tray As NotifyIcon

    Public Sub Main()

        Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", Application.ProductName, Application.ExecutablePath, RegistryValueKind.String)


        'CREATE INSTANCES OF OBJECTS WE NEED
        MyNotifyIcon = New NotifyIcon
        MyContextMenu = New ContextMenu
        'MyTimer = New Timer

        MyNotifyIcon.Icon = My.Resources.ecmsi       'SET AN ICON (ICON IS A RESOURCE IN THE PROJECT)
        MyNotifyIcon.Visible = True                 'SET VISIBLE

        'ADD CAPTIONS AND EVENT HANDLERS FOR ITEMS IN CONTEXT MENU
        MyContextMenu.MenuItems.Add("&Support Ticket", AddressOf Ticket)
        MyContextMenu.MenuItems.Add("Quick Self-Help", AddressOf SelfHelp)
        MyContextMenu.MenuItems.Add("Instant Support", AddressOf Support)
        MyContextMenu.MenuItems.Add("System Information", AddressOf SysInfo)
        MyContextMenu.MenuItems.Add("-")
        MyContextMenu.MenuItems.Add("About", AddressOf About)
        'MyContextMenu.MenuItems.Add("-")
        'MyContextMenu.MenuItems.Add("Exit", AddressOf ExitApplication)
        If (Control.ModifierKeys = Keys.Shift) Then
            MyContextMenu.MenuItems.Add("Tools", AddressOf Tools)
        End If

        MyNotifyIcon.ContextMenu = MyContextMenu        'ASSIGN CONTEXT MENU TO ICON

        'SETUP TIMER
        'MyTimer = New Timer
        'MyTimer.Interval = 10000 '10 seconds
        'MyTimer.Start()
        'AddHandler MyTimer.Tick, AddressOf Timer_Tick

        'CREATE A MESSAGE LOOP WITH NO FORM, OTHERWISE THE APPLICATION WOULD EXIT RIGHT AWAY
        Application.Run()

    End Sub

    'DELEGATE SUB TO EXIT APPLICATION
    Private Sub ExitApplication(ByVal sender As Object, ByVal e As EventArgs)
        'CLEAN UP YOUR OBJECTS
        'MyTimer.Stop()
        'MyTimer.Dispose()
        MyContextMenu.Dispose()
        MyNotifyIcon.Dispose()

        'EXIT APPLICATION LOOP
        Application.Exit()
    End Sub

    'SysInfo form
    Private Sub SysInfo(ByVal sender As Object, ByVal e As EventArgs)
        Dim SysInfo As New formSysInfo
        SysInfo.Show()
    End Sub

    'Self Help form
    Private Sub SelfHelp(ByVal sender As Object, ByVal e As EventArgs)
        Dim Tools As New formTools
        formTools.Show()
    End Sub

    'Support form
    Private Sub Support(ByVal sender As Object, ByVal e As EventArgs)
        Process.Start("https://weblink.com")
    End Sub

    'Ticket form
    Private Sub Ticket(ByVal sender As Object, ByVal e As EventArgs)
        Dim Ticket As New formTicket
        formTicket.Show()
    End Sub

    'Double Click Action
    Private Sub Tray_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseButtons)
        formTicket.Show()
    End Sub

    Private Sub ECMSI_Tray_DBLClk(sender As Object, e As EventArgs) Handles ECMSI_Tray.DoubleClick
        'Private Sub Tray_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ECMSI_Tray.DoubleClick
        formTicket.Show()
    End Sub

    'About form
    Private Sub About(ByVal sender As Object, ByVal e As EventArgs)
        Dim About As New formAbout
        formAbout.Show()
    End Sub

    'Hidden Tools Menu
    Private Sub Tools(ByVal sender As Object, ByVal e As EventArgs)
        Process.Start("C:\DIR1\DIR2\App.exe")
    End Sub


    'DELEGATE TO HANDLE TIMER TICKING
    'Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
    'MyTimer.Stop()
    'MessageBox.Show("Timer Ticked")
    'MyTimer.Start()
    'End Sub
End Module
Posted
Updated 25-May-20 6:11am
v2

1 solution

If you create a shortcut on the desktop you can edit it to add parameters that are passed to the application when it is started. You need your application to check for any parameters and deal with them accordingly. See Environment.GetCommandLineArgs Method (System) | Microsoft Docs[^] for how to get the parameters in your startup.
 
Share this answer
 
Comments
Maciej Los 25-May-20 17:05pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900