0% found this document useful (0 votes)
27 views3 pages

Form1 Form Thread: Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class

The document defines two Windows forms classes Form1 and Form2. Form1 handles user login validation and opens Form2 on a successful login by starting a new thread. It uses a progress bar and timer to close itself and launch Form2 on a separate thread after the progress bar reaches 100%. Form2 simply defines a basic form with a button to close itself.

Uploaded by

Clark Quay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Form1 Form Thread: Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class

The document defines two Windows forms classes Form1 and Form2. Form1 handles user login validation and opens Form2 on a successful login by starting a new thread. It uses a progress bar and timer to close itself and launch Form2 on a separate thread after the progress bar reaches 100%. Form2 simply defines a basic form with a button to close itself.

Uploaded by

Clark Quay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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;
using System.Threading;

namespace OpenCloseForm
{
public partial class Form1 : Form
{
Thread th;
string uname = "gilbert", pword = "david";

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (uname != textBoxUname.Text && pword != textBoxPassword.Text)
{
MessageBox.Show("Invalid username or password");
textBoxUname.Clear();
textBoxPassword.Clear();
textBoxUname.Focus();
}
else
{
this.timer1.Start();
}

private void opennewform(object obj)


{
Application.Run(new Form2());
}

private void timer1_Tick(object sender, EventArgs e)


{
this.progressBar1.Increment(1);

if (progressBar1.Value >= 100)


{

this.Close();
th = new Thread(opennewform);
th.SetApartmentState(ApartmentState.STA);
th.Start();
timer1.Enabled = false;
}

}
}
}
namespace OpenCloseForm
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
this.Close();}}}

You might also like