I'm making a simple CPU Usage monitor. The application is just an icon in the task bar which uses the Microsoft.WindowsAPICodePack library to display the CPU Usage of a task as an icon progress bar.
This application is currently working fine. For added value, I want to prevent the user from opening the application's form, which is blank. Currently I'm using the following code:
/// <summary>
/// Forces this window to remain minimized.
/// </summary>
private void MainForm_SizeChanged(object sender, EventArgs e)
{
if (WindowState != FormWindowState.Minimized)
WindowState = FormWindowState.Minimized;
}
This causes the form to flash on the screen for an instant and shrink back to the task bar. I'd prefer for absolutely nothing to visibly happen when the icon is clicked. Is there a way to achieve this?
Attempt 1
Following deathismyfriend's advice, I tried to hide the form. The WindowsAPICodePack throws an exception:
A valid active Window is needed to update the Taskbar.
Attempt 2
Setting this.Opacity = 0
didn't quite work. Funnily enough, the form is transparent... until you minimize it. Then it appears and shrinks to the task bar.