Detailed explanation of C switching window

  • 2021-09-16 07:50:24
  • OfStack

Recently, the project is not very busy, so take some time to consolidate the problem of switching windows. Interested friends follow this site 1 to learn!

1. The first method is relatively simple and cute, which I accidentally discovered recently ~


public MainFrom_Client()
{
InitializeComponent();
SetMainTreadState();
}
// First set the main form (that is, MainFrom_Client ) and taskbar status 
private void SetMainTreadState()
{
// This is actually a smoke screen! Put the main form (that is, MainFrom_Client ) Make invisible, 
// Just put Opacity The change came out, haha haha haha 
this.Opacity = ;
// Then the display of menu bar running is also invisible 
this.ShowInTaskbar = false;
}
private void ResetMainThreadState()
{
this.Opacity = ;
this.ShowInTaskbar = true;
// Just bring the current control to the front 
this.BringToFront();
}

At this time, the form is invisible, so you can reset one function at will, and call ResetMainThreadState () function when a specific condition is met, so that the main form MainFrom_Client will be displayed ~

Meng Meng's way of stealing the bell ~

2. There is also a real form call problem (after checking the knowledge for a long time, the baby is exhausted T ^ T)

My Program. cs file, first determine the first login interface Login_interface ().


static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Login_interface login_ = new Login_interface();
login_.Show();
Application.Run();
} 

Application. Run (new Login_interface ()) are all found in Program. cs files; So the big problem is, If I enter the user interface from the login interface and want to close the login interface, the system will automatically think that you have quit the program, so I can't enter the user interface. At this time, if I have to enter the user interface, I can use a method like 1, hide and other ways to not display the login interface.

This method is actually good, but I am a little dead, so I must close the login interface, so I set Application. Run () in Program. cs; In this way, how I "abuse" the login interface later will not affect the continued use of the program.

Then there is my login interface program ~ Simple ~


#region  Enter the user interface from the login interface 
private void button_Click(object sender, EventArgs e)
{
if (textBox_UserName.Text == "" && textBox_PassWord.Text == "")
{
this.Close();
User_Panel fm = new User_Panel();
fm.Show();
}
else
{
MessageBox.Show(" Wrong username and password, please re-enter ");
}
}
#endregion

The above content is related to the introduction of C # switching window, hoping to help everyone!


Related articles: