How to make the main form invisible c#

Asked

Viewed 554 times

0

How do I make the main form created by Visual Studio invisible after opening another one? I tried to use the "Hide();" command, but I was unsuccessful.

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.
    }
}
}

2 answers

4


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

    private void button3_Click(object sender, EventArgs e)
    {
        Form2 f = new Form2();
        f.Show();
        this.Hide();
    }

1

Good is also possible like this, 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;

        }
  • I believe that the property Opacity varies between 0.0 and 1.0 but if it is to hide the form, it has to be in Hide even, this way, it becomes invisible even more accessible.

  • But it is not the answer and yet another curiosity. Even with showDialog() it becomes accessible.

  • I understand that it is just curiosity, but only to leave registered for future readers, and without getting into the issue of Showdialog (that there the bottom will not be accessible), just commenting on the same Opacity.

  • 2

    You are right. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.