Code Behind the Control Box Minimise button

oafc0000

Member
Joined
Jan 28, 2003
Messages
18
Hi guys and girls

How do you put code behind the Form Control Box minimise and maximise buttons.

Basically I want to minimise the Form so it goes into the system tray but having to do it with a button at the moment coz I cant do it using the forms Control Box.

Any suggestions?

Thanks
 
Yep - still the Resize event. You want the forms WindowState property, as in:

C#:
private void Form1_Resize(object sender, System.EventArgs e)
{
	if(this.WindowState==FormWindowState.Minimized)
	{
		// Do your custom minimize to tray
		Debug.WriteLine("min");
	}
}
[edit]fixed code tags to use the [cs] [/cs] tags[/edit]
-Nerseus
 
Last edited by a moderator:
Hey guys, Ive been fighting with minimizing to the tray for a bit, heres what Ive got:


Code:
this.TrayIcon = new System.Windows.Forms.NotifyIcon(this.components);

Code:
this.TrayIcon.ContextMenu = this.TrayMenu;
this.TrayIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("TrayIcon.Icon")));
this.TrayIcon.Text = "Remote File Manager";
this.TrayIcon.Visible = true;



Now, when I minimize the application, it shows up on the botton left corner of the desktop:

[Broken External Image]:http://www.weblocke.net/rfm/example.png

How can I get rid of that? Thanks for reading ^.^
 
Ive never done Tray Icons before.. so this is just a shot in the dark. :) Would setting the form to visible = false work?

edit;
Browsing about (curious about Tray Icons now..) I found this;
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp06102002.asp

scroll down to the bottom...

The first two steps to do this are easy. You set the ShowInTaskbar property to false and the WindowState to minimized, and the window vanishes. Thats not the whole story, however, as you can still get to the window using the ALT+TAB key combination.

After a few Google searches, I came across the code to fix this problem. You need to tell the window that its a tool window, and then it isnt put into that list. I did that with a bit of code that calls out to the Win32
 
Last edited by a moderator:
Turning it to FixedToolWindow didnt work and I cant seem to find any of this code for SendMessage() to use as an example. You cant be serious in telling me something so seemingly simple is such a difficult feat for a programming language like c# =p
 
Okay, so maybe it was fairly easy. And the visible thing did work. I thought it was only available for form items, not the form itself.

this.Visible = false;
 
Back
Top