Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Sub main + Howto Execute code when app is closed

 

Ok,

How do i use sub main to do:

Check to see if a valeu in the reg is 1 or 0

If it is 0, show a form, if it is 1 then show a notifyicon.

btw: the notify icon is on the form :s

I have a temp fix, but it us irritating that the form flashesa few times befor it disapears :confused: :eek:

btw: you can look at the latest stabel code here:

http://users.skynet.be/jorge/apachemon/apachemon-src.zip

Thanx in advance

Edited by jorge
Posted

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vatskreadingwritingtoregistryusingvisualbasic.asp

 

That may help you. Its the msdn library article on reading and writing the Windows Registry. I also have some sample code I derived from that.

 

Dim regConfig As RegistryKey

regConfig = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Merck\\MRL LADI\\WPPDR", True)

If regConfig Is Nothing Then
           Registry.LocalMachine.CreateSubKey("SOFTWARE\\Merck\\MRL LADI\\WPPDR")
           regConfig.CreateSubKey("Config")
           GoTo nofile
       End If

       strConfigFile = regConfig.GetValue("Config")

 

NoFile:

With OpenFileDialog1
               .InitialDirectory = "..\Config"
               .Filter = "PD Rating Configuration (*.ini)|*.ini"
               .ShowDialog()
               strConfigFile = .FileName()
           End With
           regConfig.SetValue("Config", strConfigFile)

Posted

Okay I was misunderstanding what you wanted.

 

If someRegValue = 0 Then
         Dim you as new frmSomeForm
         you.show()
ElseIf someRegValue = 1 Then
         someicon.visible = True
End If

 

This is all I can think of. If its a taskbar icon I never used those, and don't know how to show/hide it. but the form part works.

  • Administrators
Posted (edited)

Just had a quick look (with a compiler handy yipee!!!)

Application.Run(you) does indeed display the form.

the following may be of some help though...

Dim you As New frmSomeForm
If someRegValue = 0 Then
        you.show()
ElseIf someRegValue = 1 Then
         you.someicon.visible = True        'with someicon being a notifyicon component of form1 declared public
End If

application.run()

 

the only problem is that the app doesn't exit when you close the form - either add a handler for the Form close event or deal with it in you're exit routine.

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Found it :p

 

   Sub main()
       Dim frmMain As New main()
       If sAM_tray_start = 0 Then
           frmMain.Show()
       ElseIf sAM_tray_start = 1 Then
           frmMain.systray.Visible = True
       End If
       Application.Run()
   End Sub

Thanx a lot :p

And for the closing problem:

Private Sub main_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       End
   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...