SoFunction
Updated on 2025-03-06

Detailed explanation of C# switching window

I haven't been busy with projects recently, so I took some time to consolidate the switching window problem. Interested friends will follow the editor to learn!

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

public MainFrom_Client()
{
InitializeComponent();
SetMainTreadState();
}
//First set the transparency and taskbar status of the main form (i.e. MainFrom_Client)private void SetMainTreadState()
{
//This is actually a trick!  Make the main form (i.e. MainFrom_Client) invisible.//Just change Opacity to come out, hahahahahahahahahahahahahahaha = ;
//Then the display running in the menu bar is also invisible = false;
}
private void ResetMainThreadState()
{
 = ;
 = true;
// Just bring the current control to the front();
}

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

Cute way to cover your ears and steal the bell~

2. Another thing is the real form call problem (I have been checking for a long time and I am exhausted from the baby T^T)

For my file, first determine the login interface that appears first.

static void Main()
{
();
(false);
Login_interface login_ = new Login_interface();
login_.Show();
();
} 

In general files, there is (new Login_interface()); and the biggest problem is that 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 logged out of 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, hiding and other methods to prevent the login interface from being displayed.

This method is actually good, but I am a bit stubborn, so I must close the login interface, so I set it (); in this way, no matter how I log in to the interface later, it will not affect the continued use of the program.

Then there is my login interface program~ It's simple~

#region Enter the user interface from the login interfaceprivate void button_Click(object sender, EventArgs e)
{
if (textBox_UserName.Text == "" && textBox_PassWord.Text == "")
{
();
User_Panel fm = new User_Panel();
();
}
else
{
("Username and password are incorrect, please re-enter");
}
}
#endregion

The above content is a related introduction to the C# switching window, I hope it will be helpful to everyone!