Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
Haven't tried this in .NET but in VB6 I would use the forms Resize event and check the status of its WindowsState property.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

  • *Experts*
Posted (edited)

Yep - still the Resize event. You want the form's WindowState property, as in:

 

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

Edited by John
"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • 2 months later...
Posted

Hey guys, I've been fighting with minimizing to the tray for a bit, here's what I've got:

 

 

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

 

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:

 

http://www.weblocke.net/rfm/example.png

 

How can I get rid of that? Thanks for reading ^.^

Can't afford to be neutral on a moving train...
Posted (edited)

I've 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. That's 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 it's a tool window, and then it isn't put into that list. I did that with a bit of code that calls out to the Win32® SendMessage() API.

 

When I was writing this up, I was complaining to a co-worker that I had to do this to make the window disappear. We did some more searching and found that one of the border styles you can set for a form is FixedToolWindow. I used that code instead of my SendMessage() code, and the window was gone. I thought that was the solution, but it turns out that if you bring up another window in the application, the main window will reappear. However, the main window won't show up again if you use the SendMessage() solution, so that's what I've kept. If you aren't going to bring up other windows, setting the border style should work fine.

 

Edited by wyrd
Gamer extraordinaire. Programmer wannabe.
Posted
Turning it to FixedToolWindow didn't work and I can't seem to find any of this code for SendMessage() to use as an example. You can't be serious in telling me something so seemingly simple is such a difficult feat for a programming language like c# =p
Can't afford to be neutral on a moving train...
Posted

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;

Can't afford to be neutral on a moving train...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...