karthik
karthik

Reputation:

How to hide a form

I want to hide my form when I press a button inside the form. When I do this, something must be shown in the taskbar, and if I click that thing form will again come into visible state.

Edit: I am not supposed to minimize or resize the form.

Upvotes: 0

Views: 1465

Answers (6)

Jsncrdnl
Jsncrdnl

Reputation: 3075

Use the Form's property "Opacity".

// Hide your windows frame
form1.Opacity = 0; 

/*
 * Your actions Here
 */

// Show your windows frame
form1.Opacity = 1.0;

Upvotes: 0

John B
John B

Reputation: 1179

As nils said.

Hide();
// or 
Visible = false;

NotifyIcon trayIcon;
//....
trayIcon.Visible = true;

Show/hide the trayicon depending on forms visibility.

Upvotes: 1

Franci Penov
Franci Penov

Reputation: 76001

You have two options:

  1. Use the standard minimizing behavior of the Windows Forms. In your button click handler, set the Form.WindowState property to FormWindowState.Minimized or just let the user use the standard minimize button. This will "hide" the form, but will leave its button on the taskbar, and the user can click it to bring the form back.

EDIT: Based on your question edit, you should use NotifyIcon.

  1. Close the form and add a notify icon in the task bar notification area (aka "system tray"). To do that, you need to add an instance of the NotifyIcon component to your form. Then, on your button click handler, you will call Form.Close to close the form. When the user wants to bring the form back, they will click on the syastem tray icon representing your app and you will open the form.

Here's an VB.NET example of how to do this. It shouldn't be hard to translate in C#. You can also search for NotifyIcon to see more examples.

Upvotes: 6

NileshChauhan
NileshChauhan

Reputation: 5569

//this is Form object
//Option 1

this.Hide();

//Option 2

this.Visible = false;

Upvotes: 2

White Dragon
White Dragon

Reputation: 1267

in the button code:

        FormBorderStyle = FormBorderStyle.None;
        Width = 0;
        Height = 0;

in say... the Activated form event:

        FormBorderStyle = FormBorderStyle.Fixed3D;
        Width = 800;
        Height = 500;

Would this effect be right for you?

Upvotes: 1

Alexander Prokofyev
Alexander Prokofyev

Reputation: 34515

Does standard minimize button comply with the requirements?

Upvotes: 1

Related Questions