How to hide WinForm in C#

By FoxLearn 6/8/2024 3:07:23 AM   8.61K
In C#, you can hide a WinForm after it run by using the Hide() method of the form.

Here's how you can do it:

Open your Visual Studio, then click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "HideApplication" and then click OK

Open your form designer, then add a Form1_Show and Form1_Load event handlers as shown below.

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.Threading;

namespace HideApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            //Hide your windows forms application
            this.Hide();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Thread.Sleep(5000);//5s
            MessageBox.Show("You can't see me !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}

These methods are useful for controlling the visibility of your WinForms in C#.

VIDEO TUTORIAL