473,836 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide() vs setting WindowState = FormWindowState .Minimized

mac
Brand Newbie Alert!

I am working through the "Build a Program Now!" book by Microsoft Press.
The last chapter has a little app that should stay in the system tray when
the user clicks on the 'X' to close the form. It should only shutdown when
the user chooses an option from the context menu.

The book suggests writing code in the FormClosing event of the form "Main"
to modify the behavior of the 'X' menu on the form. I have reproduced the
code here:

private void Main_FormClosin g(object sender, FormClosingEven tArgs e)
{
if (e.CloseReason == CloseReason.Use rClosing)
{
e.Cancel = true;
this.Hide(); // Book says to Hide() the form.

/*this.WindowSta te = FormWindowState .Minimized;
* I was inclined to set the WindowState instead. Is
* there a difference, and which approach is better?
*/
}
}
As I indicate in my comments, my first thought was to set the WindowState.
Which one makes more sense, and is there a difference?

Thanks,

Mac

P.S. Is it okay to send HTML in newsgroups, or is that bad form? I know it
makes the messages more readable, but are there a lot of front ends that can
only read plain text?
Jun 21 '06 #1
4 9009
> Which one makes more sense, and is there a difference?

Depends on a few things; if showing modally (ShowDialog()), then Hide()
will be the same as Close(), in that the dialog will die. Minimised
forms will show in the task-bar (if ShowInTaskbar == true); they may
appear differently in task manager too.

So it depends how you want it to behave.

Marc

Jun 21 '06 #2
Setting WindowState to Minimized is like minimizing a form, there's
(usually) an icon on the taskbar that you can restore it. Hide() will make a
form invisible, so it just disappeared. They're just different concept.

See here for explaination of their behaviour:
http://msdn.microsoft.com/library/de...owfeatures.asp

For your case, minimize the window would be better.

"mac" <ma*@mac.com> ¼¶¼g©ó¶l¥ó·s»D: E55mg.551$Nv.27 5@fed1read10...
P.S. Is it okay to send HTML in newsgroups, or is that bad form? I know
it makes the messages more readable, but are there a lot of front ends
that can only read plain text?

It depends.

Not only the news client may not support HTML format, if the newsgroup is
subscribed by other Bulletin Board System, your post will be presented as
complete garbage to them.

So in general, I'll advise NOT to use HTML format when posting in
newsgroups, as you'll get better chance for questions to be answered.
Jun 21 '06 #3
Hi,
private void Main_FormClosin g(object sender, FormClosingEven tArgs e)
{
if (e.CloseReason == CloseReason.Use rClosing)
{
e.Cancel = true;
this.Hide(); // Book says to Hide() the form.

/*this.WindowSta te = FormWindowState .Minimized;
* I was inclined to set the WindowState instead. Is
* there a difference, and which approach is better?
*/
}
}
As I indicate in my comments, my first thought was to set the WindowState.
Which one makes more sense, and is there a difference?
What is what you want to do?
Hide just hide the form, which is equivalent to set visible to false. In a
form it will dissapear from the taskbar
If you minimize it you still can see the form in the taskbar and an ALT+TAB
will allow you to navigate again to it.

Thanks,

Mac

P.S. Is it okay to send HTML in newsgroups, or is that bad form? I know
it makes the messages more readable, but are there a lot of front ends
that can only read plain text?


I think that almosteverybody can read HTML, but some pundits may says that
you should post in plain text.
Jun 21 '06 #4
mac
Thanks all for the help. I was having trouble seeing the difference until
Ignacio mentioned being able to get to minimized window via ALT TAB. I had
the ShowInTaskbar property set to False, but I didn't think about ALT TAB.

Hide() is what I need and I apprciate all the help.

Thanks,

Mac
Jun 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
51712
by: amil [c#newbie] | last post by:
Hi all, I am using the Notify Icon sample that came with .Net Docs and was able to run it. However, I want to start the form as minimized. I have the ShowInTaskbar = false and in the this is my code in the form load: private void Form1_Load(object sender, System.EventArgs e) { this.WindowState = FormWindowState.Minimized; this.Visible = false;
1
9005
by: ywchan | last post by:
I have set the ShowInTaskBar property of the form to false but it still appear when minimized... I want to have a similar effect as ICQ, when double click on the notify icon, the form appears and when minimized, it is completely disappeared.... What should I do in order to have such effect? Thanks.
2
10375
by: Li Pang | last post by:
When a form is hide, I'd like to check if it's in hide mode. How? Thanks
2
7646
by: Terry Olsen | last post by:
Using the below code, If I use Me.WindowState=Minimized the program runs fine, but you have the taskbar showing the program running. If I use Me.Hide instead, the program immediately exits. If UCase(Microsoft.VisualBasic.Command) = "/SILENT" Then Me.WindowState = FormWindowState.Minimized silent = True For i As Integer = 0 To clbPCs.Items.Count - 1 clbPCs.SetItemChecked(i, True)
6
14172
by: MJB | last post by:
I have an application that I need to hide at startup in the system tray. I found this article on how to do it: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtsksettingformtobeinvisibleatitsinception.asp The problem with this method is that when I call the Hide() function on f1 it causes the form to close which exits the app. Any other approaches to hiding the form at startup would be appreciated. Thanks
2
3394
by: Alistair George | last post by:
Hi in Delphi its a piece of cake to show and hide a mainform eg mainform.show mainform.hide. However, after finding similar actions in C# seem to result in destroy of form object, which causes errors maybe I am wrong, but here is what I have tried with no joy: private void TrayFormShow_Click(object sender, EventArgs e) { frmMain.ActiveForm.ShowInTaskbar = true; frmMain.ActiveForm.WindowState = FormWindowState.Maximized; // or: ...
2
2011
by: jp2group | last post by:
I have a Main Form that hides in the Task Bar Tray as an Icon until one of the Tray Icon's Menu Items is selected. (think of your antivirus program running there) The program starts up fine and shows the main form fine, but once I tell it to hide, it does not want to show back up later. What could my problem be? Here is my code:
8
16100
by: Andrus | last post by:
..NET 2 Winforms application. How to create new setting and set it default value in userSettings section of app.config file or overwrite existing setting value ? I found code below in this list which modifies Application setting section but how to add new item to userSettings ? Andrus.
20
4562
by: ziycon | last post by:
I have this code and when i minimise the application should disappear from the taskbar and only be visible in the tray and when i double click on the tray icon it show maximise the app. but neither functions are working, i can display the notifyicon in the tray fine, thats it!?? private void Form_Resize(object sender, System.EventArgs e) { if (FormWindowState.Minimized == WindowState) this.ShowInTaskbar = false; if...
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10549
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9376
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5650
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.