Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I cannot use Hide() or the visible property in the constructor or Load() to hide my form when it is initializing.

 

I cannot leave out the constructor code because this program runs in the background. The form needs to be initialized but I don't want the user to see it until they click the notify icon.

C#
  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

  • Moderators
Posted
Is your problem/question related to running your application on your own computer or on being able to run it on other machines... While the other machines do Not have Visual Studio .Net installed?
Visit...Bassic Software
Posted

Well anyway the answer to hiding the form on startup is.

 

Set the windows state to minimize on startup

Hide it from the task bar

 

then when you show the form

restore the windows state to normal then

show

 

Thats the easiest way I have found to do it.

Posted

Thanks TreasonX. I already tried that. The problem is that the form is still accessable to the user that way. All they have to do is use Alt + Tab to veiw any open form in windows.

 

There has got to be a better way.

C#
Posted

i tired getting that to work same problem as u

so i used a OnPaint event and hide the form

 

my app paints the panel

 

so i just used a boolean

and set it to true once it had hid the form on startup once and then on exit set it back to false so that it will work the next time

  • 2 weeks later...
Posted

Hey guyyyyysss!! I found the answer to this question and it is muuuuuch better than minimising the form and hiding the taskbar box. I was looking and reading some info here:

http://www.syncfusion.com/FAQ/WinForms/

and found out about this great resource in VS help:

search for this: Setting a Form to Be Invisible at Its Inception

 

Now, the problem is that I need to know if windows is closing the form or if the user is because windows will not restart when the form is running unless I use Application.Exit().

 

How can I tell how the form is being closed?

C#
Posted

Have a problem.

private void UserShutdown(object sender, SessionEndingEventArgs e)
{
MessageBox.Show("exit");
Application.Exit();
}
//-------------------------------
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel=true;
this.Visible=false;
MessageBox.Show("closed");
}

Here is what happens in the background (I beleive). The user attempts to restart the computer. First the Form1_Closing ev is called. It cancels the close event, making windows stop shutting down. Because of that, the UserShutdown ev is not called at all.

 

How can I tell from the Closing ev that the user is trying to shut down? Is there a way I can wait on that event? Or maybe there is another way? What do you think?

C#
  • *Gurus*
Posted

Hmm, that's weird. If the Closing event is fired before the Shutdown event, I don't know what to tell you.

 

Come to think of it, try checking Environment.HasShutdownStarted in your Closing event, perhaps that'll do it.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted (edited)
The command HasShutdownStarted must be VB because it is not there. Nevermind, it is not static. I think that is why it was not in the list. I will try it. Edited by aewarnick
C#
Posted (edited)

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)

{

Environment E=new Environment();

MessageBox.Show( "closed "+E.HasShutdownStarted );

e.Cancel=true;

this.Visible=false;

}

 

I get this error:

D:\My Documents\C Sharp projects\WallPaperRotator\Form1.cs(873): 'System.Environment.Environment()' is inaccessible due to its protection level

Edited by aewarnick
C#

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...