如何在各项控件输入和输出

一丶textbox控件

  1. 输入:直接在窗体显示的textbox控件中输入。
  2. 输出:在后台代码要输入text属性等于要输出的值。

例如textbox1.textt=”在此输入要输出的值”。

  1. textbox的示例:

第六周学习笔记

 

 

二、Label控件

1.输入:在Label的text属性中输入要输入的值。

2.输出:在后台代码写出text的属性等于要输出的值,

        例如:Label1.text=”在此输入要输出的值”。

  1. 示例:

第六周学习笔记

 

三、ComboBox控件

1.输入:使用ComboBox控件中的Items集合的Add方法向控件中添加数据

2.输出:同样为ComboBox.text=”此处输入要输出的值”。

3.示例:

第六周学习笔记

 

四、dateTimePicker日期控件
主要依赖于Value属性,在设置value属性后进行输入和输出

示例:第六周学习笔记

 

 

五、datagridview控件

该控件为数据表控件,在连接数据库后产生表格形式输出,同时输入代码对表格内数据进行修改。

代码如下:

            SqlConnection sqlConnection = new SqlConnection();                                             

            sqlConnection.ConnectionString =

                "Server=(local);Database=EduBaseDemo;Integrated Security=sspi";                            

            SqlCommand sqlCommand = new SqlCommand();                                                      

            sqlCommand.Connection = sqlConnection;                                                         

            sqlCommand.CommandText = "SELECT * FROM tb_Class;";                                            

            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();                                          

            sqlDataAdapter.SelectCommand = sqlCommand;                                                     

            DataTable classTable = new DataTable();                                                        

            DataTable studentTable = new DataTable();                                                      

            sqlConnection.Open();                                                                           

            sqlDataAdapter.Fill(classTable);                                                               

            sqlCommand.CommandText = "SELECT * FROM tb_Student;";                                          

            sqlDataAdapter.Fill(studentTable);                                                             

            sqlConnection.Close();                                                                          

            this.StudentTable = studentTable;                                                              

            this.dgv_Score.Columns.Clear();                                                                 

            this.dgv_Score.DataSource = studentTable;                                                      

            this.dgv_Score.Columns["No"].HeaderText = "学号";                                              

            this.dgv_Score.Columns["Name"].HeaderText = "姓名";

            this.dgv_Score.Columns["Gender"].HeaderText = "性别";

            this.dgv_Score.Columns["BirthDate"].HeaderText = "生日";

            this.dgv_Score.Columns["Speciality"].HeaderText = "特长";

            this.dgv_Score.Columns["Photo"].HeaderText = "照片";

            this.dgv_Score.Columns["ClassNo"].Visible = false;                                             

            DataGridViewComboBoxColumn classColumn = new DataGridViewComboBoxColumn();                     

            this.dgv_Score.Columns.Add(classColumn);                                                       

            classColumn.Name = "Class";                                                                    

            classColumn.HeaderText = "班级";                                                                

            classColumn.DataSource = classTable;                                                           

            classColumn.DisplayMember = "Name";                                                             

            classColumn.ValueMember = "No";                                                                

            classColumn.DataPropertyName = "ClassNo";                                                      

            classColumn.DisplayIndex = 4;                                                                  

            classColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;                            

            this.dgv_Score.Columns[this.dgv_Score.Columns.Count - 2].AutoSizeMode =                        

                DataGridViewAutoSizeColumnMode.Fill;

        }

 

六、picturebox控件

    为图像输出控件,在输入代码后可以打开相对应的图片

代码如下:

            OpenFileDialog openPhotoDialog = new OpenFileDialog()                                           

            {                                                                                          

                Title = "打开照片文件(位图格式)"                                                     

                ,

                Filter = "JPG Files (*.jpg)|*.jpg"                                                   

                ,

                InitialDirectory = @"C:\"                                                            

            };

            if (openPhotoDialog.ShowDialog() == DialogResult.OK)                                          

            {

                this.PhotoFileName = openPhotoDialog.FileName;                                             

                this.ptb_Photo.Image = Image.FromFile(this.PhotoFileName);                                 

            }

示例:

第六周学习笔记

 

 

七。、ListBox控件
此控件为下拉列表控件
输入:在对items属性进行输入可以得到。

        输出:同上面方法可以由text属性进行输出,。

 

 

思维导图:

第六周学习笔记

 

 

 

相关文章:

  • 2021-04-24
  • 2021-09-13
  • 2021-07-27
  • 2021-06-06
  • 2022-12-23
  • 2021-12-20
  • 2022-01-15
  • 2022-02-17
猜你喜欢
  • 2022-01-16
  • 2022-12-23
  • 2022-01-04
相关资源
相似解决方案