public void UpdatePanelContact() { try { Label lblInfo = new Label(); lblInfo.Text = "Contacts :"; lblInfo.Location = new System.Drawing.Point(8, 4); lblInfo.Size = new System.Drawing.Size(100, 16); pnlContacts.Controls.Clear(); pnlContacts.Controls.Add(lblInfo); int i = 20; statusBar.Text = "Updating Contact panel..."; string sql = "SELECT * FROM tbContactList WHERE loginName!=@loginname"; SqlCommand SqlCommand1 = con.CreateCommand(); SqlCommand1.CommandText = sql; SqlCommand1.Parameters.Add("@loginname", SqlDbType.VarChar, 100); SqlCommand1.Parameters[0].Value = TempClass.username; SqlDataAdapter adp = new SqlDataAdapter(); adp.SelectCommand = SqlCommand1; DataSet ds = new DataSet(); adp.Fill(ds, "tbContactList"); int var = ds.Tables["tbContactList"].Rows.Count; for (int j = 0; j < var; j++) { OnlineContact.UserControl1 temp = new OnlineContact.UserControl1(); temp.Contact = ds.Tables["tbContactList"].Rows[j]["loginName"].ToString(); string str = ds.Tables["tbContactList"].Rows[j]["userStatus"].ToString(); if (str == "Online") { temp.Online = true; } else { temp.Online = false; } temp.Location = new System.Drawing.Point(8, i); temp.Size = new System.Drawing.Size(pnlContacts.Width - 32, 16); temp.DoubleClick += new System.EventHandler(this.Contact_Click); pnlContacts.Controls.Add(temp); i += 18; } statusBar.Text = "Contacts updated."; } catch (Exception ex) { MessageBox.Show("Error"); } }
private void pnlContacts_Resize(object sender, EventArgs e) { OnlineContact.UserControl1 o = new OnlineContact.UserControl1(); o.Width = pnlContacts.Width - 32; }