Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
For Each arg As String In Environment.GetCommandLineArgs()
    If arg.ToLower = "-tray" Then
        Me.Hide()
        MsgBox("You have run -tray")
    End If
Next 


The above code does not work.

'-Tray' run as Although the work Me.Hide events,

Form is not hidden.

I runned like a 'C:\Users\Owner\Documents\Visual Studio 2005\Projects\CommandStart\bin\Debug\CommandStart.exe -tray'.

I saw the MsgBox is shown.
But, form is not hidden.



How Can I Do?
Posted
Updated 26-Apr-10 3:54am
v2

You are probably running this code too early, before the form is actually shown. So, it's hidden, then it's still shown by the sequence of events when the form loads. I'd try to Load event and if that does not work, look for an event that fires when the form is first shown.
 
Share this answer
 
What do I do?

If the event run so fast, I do not know how to solve it.

I create and run into another Sub, But, It still dosen't work.
 
Share this answer
 
You should not press 'answer' to ask more questions. You should perhaps buy a book on winforms. Your form generates events. They occur when certain things happen in the lifecycle of your form. You are running this code before the form is shown by the framework. Your code needs to run AFTER the framework shows the form. So you need to work out the right event to run your code in, for this to happen. I think the Load event is a good place to start.
 
Share this answer
 
I think to help you properly is to understand what you are trying to do?

i have put your code in to the load of a form that i have open and it works like you have explain.
 
Share this answer
 
Normally, a form is not displayed until Show or ShowDialog is called. The one exception is the main form, which can be minimized but not hidden.

You can write formless applications in VB.Net (probably C# too, but I'm not sure how to do that.) You will need to create a class based on ApplicationContext that will act as the application -- this will keep the application running without a primary form. Add a public module with the method Sub Main. In the My Project interface, uncheck "Enable application framework". Select "Sub Main" as the startup object. In Main, add the single line Application.Run with a new instance of your application context class.

I looked through the Code Project and didn't see any VB articles that demonstrate how to do this. I will work to remedy this lack of information and try to get something posted by the end of the week. In the mean time, try searching the web for "Sub Main" and "ApplicationContext" and see what you can find. If you can translate from C#, this article at CP, Creating a Tasktray Application[^] should help a lot.




Added - Article written: Create A Tray Application In VB.Net[^]. Let me know if it helps.
 
Share this answer
 
v3
The 'official' M$ way to do this is explained in Setting a Form to Be Invisible at Its Inception[^].

I've never tried it, so I don't know how effective it is.
 
Share this answer
 

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