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 (FormWindowState.Maximized == WindowState)
-
this.ShowInTaskbar = true;
-
}
-
private void notifyIconMain_DoubleClick(object sender, System.EventArgs e)
-
{
-
Show();
-
WindowState = FormWindowState.Normal;
-
}
Also can anyone tell me how to override the 'X' to minimise the app. and not exit it?
20 4501
All you are doing is changing the show in taskbar property. You shouldn't have to change that at all.
Use the .Visible property instead. -
private void Form_Resize(object sender, System.EventArgs e)
-
{
-
if (WindowState == FormWindowState.Minimized )
-
{
-
this.Visible=false;
-
}
-
}
-
private void notifyIconMain_DoubleClick(object sender, System.EventArgs e)
-
{
-
this.Visible=true;
-
WindowState = FormWindowState.Normal;
-
}
-
To stop the form closing you catch it in the form's FormClosing event...
To your second question:
You will need to handle the FormClosing Event. Use conditions to determine whether you want to close the form or not. If you do, do nothing. Otherwise, change e.Cancel to true.
Here's an example of a FormClosing event handler - private void BBCodeTextEditor_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
//if windows is shutting down, or the user ends task from the task manager, don't ask questions
-
if (e.CloseReason != CloseReason.WindowsShutDown && e.CloseReason != CloseReason.TaskManagerClosing)
-
{
-
//if my dialog is OK, then close
-
if (this.DialogResult == DialogResult.OK)
-
{
-
e.Cancel = false;
-
return;
-
}
-
//otherwise, if my cancelled flag is set, close
-
if (this.cancelled)
-
{
-
e.Cancel = false;
-
return;
-
}
-
//otherwise, if my text isn't dirty, close
-
if (this.EditorText.Equals(this.originalText))
-
{
-
e.Cancel = false;
-
return;
-
}
-
//if we got here, then we aren't sure if we want to close or not
-
else
-
{
-
string message = Properties.Resources.sCloseFormMessage;
-
string caption = Properties.Resources.sCloseFormCaption;
-
//show a dialog to ask the user
-
DialogResult res = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
-
if (res == DialogResult.No)
-
//user does not want to close, cancel closing
-
e.Cancel = true;
-
else
-
//user confirmed closing, continue
-
e.Cancel = false;
-
}
-
}
-
}
-
You can see how you use conditions to determine if you want to close or not, and how to prevent closing. I would suggest you use that first line, you don't want your app holding up Windows shutting down.
This is the code i have now and none of it works, any i doing something wrong?? - private void Form_Resize(object sender, System.EventArgs e)
-
{
-
if (WindowState == FormWindowState.Minimized)
-
{
-
this.Visible = false;
-
}
-
}
-
private void notifyIconMain_DoubleClick(object sender, System.EventArgs e)
-
{
-
this.Visible = true;
-
WindowState = FormWindowState.Normal;
-
}
-
private void Form_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
e.Cancel = true;
-
this.WindowState = FormWindowState.Minimized;
-
}
Are you sure that you have registered the event handlers?
Also, as I said in an earlier post, if you don't check to see if the close reason is windows shutdown, you can cause problems.
I don't know how to set Event handlers so thats a no!?
I don't know how to set Event handlers so thats a no!?
OK, make sure that your Form is selected in the designer window. Look in the properties menu, and click the lightning bolt. You should see something like this:
Now, find the events you want to handle, and click the dropdown, and choose the correct method.
That should work.
Genius, working now, only thing that i can't get to work is when you click on the tray icon the form wont show again, what event do i use for that 'click' mouseclick' etc??
Well, you have to select your NotifyIcon object and do the same thing. Check out the screenshot:
You can see that I have my notify icon selected, and that the properties window shows the events for it, instead of the form.
I understand you now, got all that work, last thing about his i promise.
I have this, how do i say that when the icon in the tray is clicked that the frmMain that was made this.Visible = false on minimise is shown again instead of creating a new form as i can see how the this.Visible = true would apply to the hiden form!? - private void frmMain_Resize(object sender, EventArgs e)
-
{
-
if (WindowState == FormWindowState.Minimized)
-
{
-
this.Visible = false;
-
}
-
}
-
private void notifyIconMain_Click(object sender, EventArgs e)
-
{
-
this.Visible = true;
-
WindowState = FormWindowState.Normal;
-
}
That should be correct as is, assuming that the handler functions are located withen the form's class structure. (That is the default behavior when using visual studio to attach event handlers, as insert's instructions showed)
Sorry, I don't quite understand your question. Can you please phrase it a bit more clearly?
When i click the minimise button on Form A it will make Form A 'invisible' and when i click on the icon in the Tray it will make Form A visible again, does the this.Visible = true; effect the notiyIcon or the Form A when i click on the icon in the Tray?
Its not making the Form A visible when i click the icon in the Tray with the below code: - private void notifyIconMain_Click(object sender, EventArgs e)
-
{
-
this.Visible = true;
-
WindowState = FormWindowState.Normal;
-
}
I have mouseClick and mouseDoubleClick of the notifyIcon set to the above function!??
Well, I'm not sure what's wrong with that code...
I like to do it the way you first suggested. Using this.ShowInTaskbar.
Here's what my methods for this look like: - private void BDAMainForm_Resize(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
this.ShowInTaskbar = false;
-
else
-
this.ShowInTaskbar = true;
-
}
-
-
//notify icon click event handler
-
private void niBda_MouseClick(object sender, MouseEventArgs e)
-
{
-
if (e.Button == MouseButtons.Left)
-
this.WindowState = FormWindowState.Normal;
-
}
The one difference I see is that you use an EventArgs instead of MouseEventArgs, but that shouldn't matter.
- private void BBCodeTextEditor_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
//if windows is shutting down, or the user ends task from the task manager, don't ask questions
-
if (e.CloseReason != CloseReason.WindowsShutDown && e.CloseReason != CloseReason.TaskManagerClosing)
-
{
-
//if my dialog is OK, then close
-
if (this.DialogResult == DialogResult.OK)
-
{
-
e.Cancel = false;
-
return;
-
}
-
//otherwise, if my cancelled flag is set, close
-
if (this.cancelled)
-
{
-
e.Cancel = false;
-
return;
-
}
-
//otherwise, if my text isn't dirty, close
-
if (this.EditorText.Equals(this.originalText))
-
{
-
e.Cancel = false;
-
return;
-
}
-
//if we got here, then we aren't sure if we want to close or not
-
else
-
{
-
string message = Properties.Resources.sCloseFormMessage;
-
string caption = Properties.Resources.sCloseFormCaption;
-
//show a dialog to ask the user
-
DialogResult res = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
-
if (res == DialogResult.No)
-
//user does not want to close, cancel closing
-
e.Cancel = true;
-
else
-
//user confirmed closing, continue
-
e.Cancel = false;
-
}
-
}
-
}
this.cancelled this.EditorText
Can you explain what these variables mean? They throw errors and can't figure out where there coming from!?
That was just an example from a project I'd been working on. Not meant to be a copy+paste solution, just an example of a real-life application. Those are members of my form.
I understand, thanks, I'll work it out myself then, appreciate all your help. Thanks again.
Should this not work? When a user clicks on 'X' is that not considered CloseReason.UserClosing? - private void Form_Closing(object sender, FormClosingEventArgs e)
-
{
-
if (e.CloseReason != CloseReason.WindowsShutDown && e.CloseReason != CloseReason.TaskManagerClosing)
-
{
-
if (this.DialogResult == DialogResult.OK)
-
{
-
e.Cancel = false;
-
return;
-
}
-
if ((e.CloseReason == CloseReason.ApplicationExitCall) || (e.CloseReason == CloseReason.UserClosing))
-
{
-
this.Visible = true;
-
WindowState = FormWindowState.Normal;
-
}
-
}
-
}
Are you actually setting this.DialogResult somewhere?
I feel like I may have lead you down the wrong path by giving you that sample...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lalit |
last post by:
Hi Friends,
I have developed a Windows service. Now i need icon for this service in
systray and context menu fo this icon. Can i do this?
With regards,
Lalit
|
by: shagshag |
last post by:
I know how to place a notify icon in the system tray and
how to hide the Form that owe the icon. The taskbar entry
button is hidden, ok, but I always get an entry for the
Form when I press...
|
by: Claire |
last post by:
Windows refuses to close down if my applications main form is hidden and
there's a notify icon in the system tray. If I restore the form, then
shutting down Windows succeeds.
If I comment out the...
|
by: Beenish Sahar Khan |
last post by:
I want to start my application so that its notify icon is added to the
system tray, i don't want to show any starting form. I want user to interact
through the notify icon...just like MSN. Is there...
|
by: sanjana |
last post by:
hi
i want to write a C# .net code to display a balloon in the task bar
i have used notifyicon class to get the icon in the task bar
then i have used Shell_NotifyIcon and NotifyIconData structure...
|
by: Rob |
last post by:
I have an interesting problem with my Notify Icon. I cannot get it to
display when I start a web service. I have no problems when I test the
software on a Windows program. But the Icon will not...
|
by: Cylix |
last post by:
I am going to make an application in monitor and do something on time.
A part of it is an Notify icon(System Tray Icon),
Which project type can I be used for Just showing the notify icon
without...
|
by: namrataa |
last post by:
i have a notify icon for our media player developed in wpf.
included files are notify.cs,notify.resx,notify.designer.cs.
i have also added a class file called app.cs .
now the problem is how...
|
by: namrataa |
last post by:
i have the following code for my notify.cs file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |