I am working on an app that I need to minimize/close to the system tray.
More or less I have the minimize to the system tray working, save caveat. When it is minimized the application still appears in the task bar. Is there a way to remove the application from the task bar?
Here is my current code for minimize. -
-
private void Form1_Resize(object sender, System.EventArgs e)
-
{
-
if (FormWindowState.Minimized == WindowState)
-
Hide();
-
}
-
Now when it comes to closing to the system tray, everything I have tried just closes the application in stead of closing it to the system tray.
Here is my current code for closing. -
-
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
-
if (e.CloseReason == CloseReason.UserClosing)
-
{
-
e.Cancel = true;
-
Hide();
-
}
-
}
-
22 17595
You are using the NotifyIcon, aren't you? Can you see your icon in the system tray after being minimized? Or, when your form loads do you see your icon at all in the system tray? Maybe you have not given it an icon reference or set it's .Visible Property to true.
joedeene
I do see the notifyicon. The issue with minimize is it shows up in the task bar as well as the system tray when minimized. I do not want it to show in the task bar if it is minimized. I only want it to show in the system tray.
Forms have a "ShowInTaskbar" attribute.
You can do something like this: -
if (FormWindowState.Minimized == WindowState)
-
{
-
Hide();
-
this.ShowInTaskbar = false;
-
}
-
I have tried this.ShowInTaskbar = false; and still shows in the task bar.
Ok got the minimize figured out, if I set the default property on the form to ShowInTaskBar to false, it does exactly what I want it to.
But I am still a bit stuck on the whole close to the system tray issue.
Ok got the minimize figured out, if I set the default property on the form to ShowInTaskBar to false, it does exactly what I want it to.
But I am still a bit stuck on the whole close to the system tray issue.
Well how are you closing the form, try taking the Close Reason If Statement out and then see, if it works experiment which ones work...
joedeene
-
namespace TestShowInTaskbar
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void Form1_Resize(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
{
-
this.ShowInTaskbar = false;
-
}
-
else
-
{
-
this.ShowInTaskbar = true;
-
}
-
}
-
-
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
-
{
-
this.WindowState = FormWindowState.Normal;
-
}
-
-
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
if (e.CloseReason != CloseReason.TaskManagerClosing &&
-
e.CloseReason != CloseReason.WindowsShutDown)
-
e.Cancel = true;
-
this.WindowState = FormWindowState.Minimized;
-
}
-
}
-
}
-
This works just fine for me. Of course, you would have to provide some mechanism for your user to exit, but that shouldn't be too hard.
Well there are several ways I want to blocking closing.
Close button in the title window, system menu close, and alt+ f4.
Every example that I have seen uses the code that I posted in my original post.
The way I posted blocks all but Task Manager closings and Windows shutdown.
Hide() is probably what is killing you.
Try it my way and see what happens.
Copied your code exactly, and still does the same thing. Here is a full breakdown of my code. -
private void Form1_Resize(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
{
-
this.ShowInTaskbar = false;
-
}
-
else
-
{
-
this.ShowInTaskbar = true;
-
}
-
}
-
-
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
-
{
-
Show();
-
WindowState = FormWindowState.Normal;
-
-
}
-
-
-
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
if (e.CloseReason != CloseReason.TaskManagerClosing &&
-
e.CloseReason != CloseReason.WindowsShutDown)
-
e.Cancel = true;
-
this.WindowState = FormWindowState.Minimized;
-
}
-
Why do you change the ShowIntaskBar property, you really want to be hide/unhide'ing the form.
Just curious, did you wire up all the events, or just paste the functions in?
@Plater, that's the way it's always worked for me.
I want both to occur. I want to hide the application and not show it in the task bar.
Well, try something like this: -
namespace TestShowInTaskbar
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void Form1_Resize(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
{
-
this.Hide();
-
}
-
}
-
-
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
-
{
-
this.Show();
-
this.WindowState = FormWindowState.Normal;
-
}
-
-
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
if (e.CloseReason != CloseReason.TaskManagerClosing &&
-
e.CloseReason != CloseReason.WindowsShutDown)
-
e.Cancel = true;
-
this.Hide();
-
}
-
}
-
}
-
Both should work perfectly, or there's something else happening in your code. I've tried and tested both, and they both work just fine for me.
I am not exactly where the issue would be in my app. I have trimmed everything not relating to the form.
So, I will just show you everything. This is all the functioning code that I am using at this time.
Program.cs -
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Windows.Forms;
-
using System.Threading;
-
-
namespace qbLinx
-
{
-
static class qbLinx
-
{
-
/// <summary>
-
/// The main entry point for the application.
-
/// </summary>
-
[STAThread]
-
static void Main()
-
{
-
bool ok;
-
Mutex m = new Mutex(true, "iqbLinx", out ok);
-
if (!ok)
-
{
-
MessageBox.Show("Another instance is already running.");
-
return;
-
}
-
-
Application.EnableVisualStyles();
-
Application.SetCompatibleTextRenderingDefault(false);
-
Application.Run(new Form1());
-
GC.KeepAlive(m);
-
-
-
//sqlConnect sqlCnn = new sqlConnect();
-
-
//sqlCnn.mysqlAddQuery();
-
}
-
}
-
}
-
Form1.cs -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Diagnostics;
-
-
namespace qbLinx
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
RegistrySettings regQry = new RegistrySettings();
-
txtbhName.Text = regQry.GetRegEntry("hostname");
-
txtbuName.Text = regQry.GetRegEntry("uName");
-
txtbuPass.Text = regQry.GetRegEntry("uPass");
-
txtbdSource.Text = regQry.GetRegEntry("hostDest");
-
txtbBrowse.Text = regQry.GetRegEntry("compFile");
-
-
-
}
-
-
private void btnBrowse_Click(object sender, EventArgs e)
-
{
-
OpenFileDialog dlgOpen = new OpenFileDialog();
-
if (dlgOpen.ShowDialog() == DialogResult.OK)
-
{
-
txtbBrowse.Text = dlgOpen.FileName;
-
}
-
}
-
-
private void btnSave_Click(object sender, EventArgs e)
-
{
-
RegistrySettings regSet = new RegistrySettings();
-
regSet.SetRegEntry("hostname", txtbhName.Text);
-
regSet.SetRegEntry("uName", txtbuName.Text);
-
regSet.SetRegEntry("uPass", txtbuPass.Text);
-
regSet.SetRegEntry("hostDest", txtbdSource.Text);
-
regSet.SetRegEntry("compFile", txtbBrowse.Text);
-
}
-
-
private void btnCancel_Click(object sender, EventArgs e)
-
{
-
Hide();
-
}
-
-
private void Form1_Resize(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
{
-
this.ShowInTaskbar = false;
-
}
-
else
-
{
-
this.ShowInTaskbar = true;
-
}
-
}
-
-
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
-
{
-
Show();
-
WindowState = FormWindowState.Normal;
-
-
}
-
-
-
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
if (e.CloseReason != CloseReason.TaskManagerClosing &&
-
e.CloseReason != CloseReason.WindowsShutDown)
-
e.Cancel = true;
-
this.Hide();
-
}
-
-
-
-
-
}
-
}
-
Well, part of the problem is you're mixing and matching between two examples. In the Resize event you are using ShowInTaskbar, and everywhere else you are using Hide/Show. Go with one mechanism or the other. Try to use my latest example as your resize event: -
private void Form1_Resize(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
{
-
this.Hide();
-
}
-
}
-
The minimize now works, but the close does not work. When I click the close button in the title window, system menu close, or alt+f4 it still closes the application.
Did you wire up that event or just copy/paste? Make sure that the method is set in the Events tab in the properties box. See the attatchment:
Yes I have the event setup, with in the events panel.
Well, I don't know what to tell you. The code works just fine on my computer. Make sure again that you are using the code only from my latest sample, and try to put breakpoints in your program and trace through it.
Sorry I can't help anymore.
If it is any help, here is the handler that I use for a couple programs that do the same thing: Don't display in task bar, close to just the notifyicon etc. - private void Form1_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
if (e.CloseReason == CloseReason.UserClosing || e.CloseReason == CloseReason.TaskManagerClosing)
-
{
-
MainLog(string.Format("Hiding. ({0})",e.CloseReason));
-
e.Cancel = true; // true that we are canceling the close event
-
this.Hide(); // same as saying this.visible = false;
-
this.ShowInTaskbar = false;
-
notifyIcon1.Visible = true;
-
}
-
else MainLog(string.Format("Closing. ({0})", e.CloseReason));
-
notifyIcon1.Visible = false;
-
}
-
If a form is hidden, or visible=false, it's taskbar entry is hidden also (as well as its position in alt+tab and in the "applications" tab of the taskmanager)
That being said, turning off the taskbar entry, ShowInTaskBar=false, is a nifty little trick, but when you minimize, it just acts as an mdichild of the desktop and leaves its little windowbar in the bottom left corner, just above the taskbar.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Manoj Nair |
last post by:
Hi,
The problem :
Have a system tray application.This has a menu item 'Exit'.
On click of this a differnt application with a UI which runs in the
background should close.
The other application...
|
by: Shawn |
last post by:
Hi. I've created an application that can run in the system tray. The way it
works now I have to click a button to "send" the application to the system
tray, but I want the application to run in...
|
by: rdi |
last post by:
I was able to get my utility to work using parts of the system tray example.
If you right click on "Show Form" my form pops up--but only if that form is
not already open.
What I'd like to...
|
by: Sidney |
last post by:
Dear,
I am writting a system which opened at the system tray. But every before
I shut down my computer,
I have to close the system first. However, it should be automatically
close when I shutting...
|
by: bipi |
last post by:
Dear everyone,
In my application, I kill process by:
private bool KillProcess(String processName)
{
bool result = false;
Process process =
Process.GetProcessesByName(processName);
for (int...
|
by: flaper87 |
last post by:
Hi everybody!!!!
I am developing an aplication, and i want it to stay on the system tray, i found out how to put the icon, but i can minimize it there, What do i have to do?, I'm using python(of...
|
by: Patrick Dugan |
last post by:
I am using VS2005 (vb) and I have a program that starts when Windows boots
up. Occasionally the icon that should appear in the system tray does not
show up. The program is still running in memory...
|
by: holaboxdotcom |
last post by:
Hey
I'm pretty new to C# (started few hours ago) but i learn extremly fast, i have previous knowledge of php, javascript and flash.
I have made my first simple application the way i want it,...
|
by: Lawyno |
last post by:
Hi there,
we are creating some automated backup solution for some user application (let's say "UserApp" ;)). Now, the backup service is working perfectly.
But there's a problem: the backups...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: 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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: 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,...
|
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...
| |