1. 程式人生 > >2017-5-15 winform項目總結(知識點補充)

2017-5-15 winform項目總結(知識點補充)

name inf tostring 總結 用法 傳值 draw ring rgs

1.groupBox

屬性重寫,增加邊框,事件paint

  

 private void groupBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(groupBox1.BackColor);
            e.Graphics.DrawString(groupBox1.Text, groupBox1.Font, Brushes.Black, 10, 1);
            e.Graphics.DrawLine(Pens.Black, 1, 7, 8, 7
); e.Graphics.DrawLine(Pens.Black, e.Graphics.MeasureString(groupBox1.Text, groupBox1.Font).Width + 8, 7, groupBox1.Width - 2, 7); e.Graphics.DrawLine(Pens.Black, 1, 7, 1, groupBox1.Height - 2); e.Graphics.DrawLine(Pens.Black, 1, groupBox1.Height - 2, groupBox1.Width - 2
, groupBox1.Height - 2); e.Graphics.DrawLine(Pens.Black, groupBox1.Width - 2, 7, groupBox1.Width - 2, groupBox1.Height - 2); }

2.用戶控件和窗體之間的傳值

在實例化用戶控件的時候,可以直接創窗體,這樣在用戶控件中就可以調用窗體之間的值,可以在窗體中聲名一個public公共的變量,用戶控件中賦值之後,在次在窗體調用

3.dataGridView控件的用法:

//取出食物信息
                List<XFood> flist = new
XFoodData().selectAll(); //賦值 foreach (XFood xf in flist) { //每一行的數據類型 DataGridViewRow row = new DataGridViewRow(); //每一行中的第一個空格的數據類型,每一個空格的數據類型可以不相同 DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell(); textboxcell.Value = xf.FoodId; //每一個空格賦值 row.Cells.Add(textboxcell); //第二個空格的數據類型 DataGridViewTextBoxCell textboxcell2 = new DataGridViewTextBoxCell(); textboxcell2.Value = xf.FoodName; row.Cells.Add(textboxcell2); //第三個空格的數據類型 DataGridViewTextBoxCell textboxcell3 = new DataGridViewTextBoxCell(); textboxcell3.Value = xf.FoodUnit; row.Cells.Add(textboxcell3); //第四個空格的數據類型 DataGridViewTextBoxCell textboxcell4 = new DataGridViewTextBoxCell(); textboxcell4.Value = xf.FoodPrice.ToString(); row.Cells.Add(textboxcell4); DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell(); comboxcell.Items.Add("1"); comboxcell.Items.Add("2"); comboxcell.Items.Add("3"); comboxcell.Items.Add("4"); comboxcell.Items.Add("5"); row.Cells.Add(comboxcell); DataGridViewCheckBoxCell checkbox = new DataGridViewCheckBoxCell(); checkbox.Value = xf.HasOk.ToString(); row.Cells.Add(checkbox); //每一行賦值 dataGridView1.Rows.Add(row);

2017-5-15 winform項目總結(知識點補充)