Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have two forms: Form1, and frmMain. Form1 is the sample code from VB .Net to get an icon to appear in the systray for your application. The following code is in Form1 and is used to unload the icon:

 

Public Sub ExitSelect(ByVal sender As Object, ByVal e As System.EventArgs)

'called when the user selects the 'Exit' context menu

 

'hide the tray icon

notifyicon.Visible = False

 

'close up

Me.Close()

End Sub

 

My main application is frmMain. When I close main, the systray icon remains. I need to be able to call ExitSelect from frmMain. I've tried Form1.ExitSelect() but it complains about their not being an object reference.

Guest mutant
Posted

Declare an instance of your Form1 and then you can use: Form1.ExitSelect()

 

Dim Form1 as new Form1
'do whatever you have to...
Form1.ExitSelect()

 

Or did you already declare it?

Posted

I tried that, actually. Since Form1 is the systray icon itself kind of (it's the form with the code to load the icon and the icon's right-click menu) any time you do Dim Blah as new Form1, it's going to create new instance of it and put a second icon in the tray.

 

Form1 is also the start-up form. Form1's OnLoad method contains code to load frmMain, my main application screen.

Guest mutant
Posted

Oh I thought frmMain was the one that starts the app :D

Make a custom constructor in the frmMain, after Form1 loads the icon, declare the frmMain and pass in the instance of Form1 to frmMain and you can then call ExitSelect.

Posted
thanks for your help.. but I am new to VB (I have a better backround in Java) and I'm not sure how to do any of that in VB. If it's not difficult, could you paste code to make a custom constructor? I'm using nearly all sample code at this point, this is a learning project that I'm working on. Thanks a lot!
Guest mutant
Posted

Try this:

dim somevariablename as Form1
Public Sub New(ByVal theform as Form1)
MyBase.New()
InitializeComponent()
'now if you want to just call ExitSelect then just type
theform.ExitSelect()
'or if you wish to use this instance somewhere else, make some 
'variable that will be public to the class and assign this form to it.
somevariablename = theform
End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...