Lecture 9 - windowsform application
Lecture 9 - windowsform application
• thread1.Start();
• thread2.Start();
• }
Sample program for thread
• private void Form1_Load(object sender, EventArgs e)
• {
• Control.CheckForIllegalCrossThreadCalls = false;
• }
• public void beta()
• {
• for (int i = 0; i <= 10000; i++)
• {
• label1.Text = i.ToString();
• }
• }
• public void alpha()
• {
• for (int i = 10000; i>=1;i--)
• {
• label2.Text = i.ToString();
• }
• }
• private void btn_st_Click(object sender, EventArgs e)
• {
• Thread thread1 = new Thread(new ThreadStart(beta));
• Thread thread2 = new Thread(new ThreadStart(alpha));
• thread1.Start();
• thread2.Start();
• }
Working with multiple forms
• private void btn_show_Click(object sender, EventArgs e)
• {
• Form2 form = new Form2();
• form.Show();
• }
System Data
Common contains
classes shared by both
SQLClient .OleDb
• public Form1()
• {
• InitializeComponent();
• }
• private void Form1_Load(object sender, EventArgs e)
• {
• con = new SqlConnection();
• con.ConnectionString = "Data Source=DESKTOP-QC7BTE6;Initial
Catalog=esoft2022;Integrated Security=True";
• }
• private void btn_insert_Click(object sender, EventArgs e)
• {
•
• clientid = txt_cid.Text;
• name = txt_cname.Text;
• address = txt_add.Text;
• tp = txt_tel.Text;
• con.Open();
• cmd = new SqlCommand("insert into client values (@client_id, @client_name,
@client_Address, @client_tel)", con);
• cmd.Parameters.AddWithValue("client_id", clientid);
• cmd.Parameters.AddWithValue("client_name", name);
• cmd.Parameters.AddWithValue("client_Address", address);
• cmd.Parameters.AddWithValue("client_tel", tp);
• int line=cmd.ExecuteNonQuery();
• cmd.Dispose();
• con.Close();
• if(line==1)
• {
• MessageBox.Show("Success");
• }
• else
• {
• MessageBox.Show("Failed");
• }
•
• }