有沒有一種方法可以讓我的主窗體form1在窗體2載入後顯示??我創建了兩個窗體窗體1是主窗體,窗體2是登錄表單我想要當用戶有正確creditials形式1應該自動加載 這是形式2代碼加載主窗體在c sharp中給出兩種形式
private void button1_Click(object sender, EventArgs e)
{
string username1 = "Richard";
string password1 = "Peugeot";
if (this.textBox1.Text == username1 && this.textBox2.Text == password1)
MessageBox.Show("Welcome Richard!", "Welcome");
else
MessageBox.Show("Incorrect username or password", "Bad credentials");
}
這是Form 1代碼
private void Form1_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(String.Empty);
sb.AppendLine("Operation System Information");
sb.AppendLine("----------------------------");
sb.AppendLine(String.Format("Name = {0}", OSVersionInfo.Name));
sb.AppendLine(String.Format("Edition = {0}", OSVersionInfo.Edition));
if (OSVersionInfo.ServicePack!=string.Empty)
sb.AppendLine(String.Format("Service Pack = {0}", OSVersionInfo.ServicePack));
else
sb.AppendLine("Service Pack = None");
sb.AppendLine(String.Format("Version = {0}", OSVersionInfo.VersionString));
sb.AppendLine(String.Format("ProcessorBits = {0}", OSVersionInfo.ProcessorBits));
sb.AppendLine(String.Format("OSBits = {0}", OSVersionInfo.OSBits));
sb.AppendLine(String.Format("ProgramBits = {0}", OSVersionInfo.ProgramBits));
textBox1.Text = sb.ToString();
}
這是Program.cs的代碼
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
我想第1到Form2的感謝後自動加載提前
'新Form1的()。展()'? – I4V
我不明白你的問題 – alexzandria
oooooooooooh我明白了讓我試試 – alexzandria