2017-5-15 winform项目总结(知识点补充)

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);

 

 

posted @ 2017-05-15 20:35  青年a  阅读(164)  评论(0编辑  收藏  举报