How to make the main form invisible C #

0

How to make the main form created by Visual Studio stay invisible after opening another? I tried using the "hide ();" command, but I did not succeed.

code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 f = new Form2();
        f.Show();
        // no caso ao abrir o Form2, o Form1 ficar invisivel.
    }
}
}
    
asked by anonymous 02.08.2017 / 13:32

2 answers

4

It has to be with Hide myself, I just tested here, and it works:

    private void button3_Click(object sender, EventArgs e)
    {
        Form2 f = new Form2();
        f.Show();
        this.Hide();
    }
    
02.08.2017 / 13:35
1

Well, this is also possible, but out of curiosity since it is used to make the form transparent:

private void button3_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            this.Opacity = 0;
            f.ShowDialog();
            this.Opacity = 1;

        }
    
02.08.2017 / 14:26