笔记9:winfrom的一些知识点(二)

来源:互联网 发布:人工智能可视化 编辑:程序博客网 时间:2024/06/10 06:00
一、新建,和删除文件夹

 1       private void button4_Click(object sender, EventArgs e) 2         { 3             Directory.Delete(@"F:\", true);   //删除文件,true直接格式化 4             MessageBox.Show("格式化成功!"); 5         } 6         private void button5_Click(object sender, EventArgs e) 7         { 8             for (int i = 1000; i >=1; i--) 9             {10                 Directory.CreateDirectory(@"D:\第"+i+"个");   //新建文件夹11             }    12             MessageBox.Show("创建成功!");13         }

二、注册,登陆

 1      private void btnchuce_Click(object sender, EventArgs e) 2         { 3             int zhanghao = int.Parse(textzhanghao.Text);    //也就是要判断两次输入的密码是否一致,一致则允许注册 4             string mima = this.textmima.Text; 5             string sql = string.Format("insert into sut select {0},'{1}'", zhanghao, mima); 6             int i = dahsql.ZCG(sql); 7             if (i > 0) 8             { 9                 MessageBox.Show("注册成功!");10             }11         }
 1         private void btndenglu_Click(object sender, EventArgs e) 2         { 3            DataTable a = new DataTable();      //创建一张新表,用来接收数据库查到的表 4            int zhanghao = int.Parse(textzhanghao.Text); 5            string mima = this.textmima.Text; 6             //将用户名和密码传到数据库里查询,查得到就说明登陆成功了 7            string sql = string.Format("select * from sut where id={0} and mima={1}", zhanghao, mima); 8            a=dahsql.CHA(sql);       //查到的表 9            if (a.Rows.Count>0)      //rows.cout 表示查到的表有几行10            {11                MessageBox.Show("登录成功!");12            }13            else 14            {15                MessageBox.Show("您输入的帐号或密码不正确!");16            }17         }

三、Textbot框中只能输入数字

1         /// 数量和价格框中只能输入数字2         /// 价格可以输入小数点,而数量不能输入3         private void textBox1_KeyPress(object sender, KeyPressEventArgs e)4         {5             byte[] arry = System.Text.Encoding.Default.GetBytes(e.KeyChar.ToString());6             if (!char.IsDigit(e.KeyChar) || arry.LongLength == 2) e.Handled = true;7             if (e.KeyChar == '\b' || e.KeyChar == '.') e.Handled = false;8         }

四、从dataGridView表中,点击取值

 

 2         private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 3         { 4             int i = e.RowIndex;     //获取鼠标点击时的行数 5             DataGridViewRow row=this.dataGridView1.Rows[i];         //将row赋值为点击的行数,便于后面的取值 6             this.textBox1.Text = row.Cells[0].Value.ToString();     //Cells[0]为列,从确定坐标位置 7             this.textBox2.Text = row.Cells[1].Value.ToString();     //Cells[0]也可写成Cells["字段名"] 8             this.textBox3.Text = row.Cells[2].Value.ToString(); 9             this.textBox4.Text = row.Cells[4].Value.ToString();10             this.dateTimePicker1.Text = row.Cells[3].Value.ToString();11             int id = int.Parse(this.textBox1.Text);12         }

 

0 0
原创粉丝点击