循环panel内的控件
删除列表选中项
if (this.listView1.SelectedItems.Count == 0)
{
MessageBox.Show("没有选中项目");
return;
}
ListViewItem item = this.listView1.SelectedItems[0];
this.listView1.Items.Remove(item);
文件操作
打开文件的属性
判断文件是否存在,存在就强行覆盖
递归调用——复制和移动文件夹及文件夹里的所有文件
//递归调用,复制和移动文件夹及文件夹里的所有文件
Directory.CreateDirectory("end文件夹名称");
DirectoryInfo startDir = new DirectoryInfo("start文件夹名称");
foreach (FileInfo item in startDir.GetFiles())
{
item.CopyTo(endfile + "\\" + item.Name);
}
foreach (DirectoryInfo item in sartDir.GetDirectories())
{
string startPath = item.FullName;
string endPath = endPath + "\\" + item.Name;
copyFolder(startPath, endPath);
}
读取文件内容并显示
//方案1
ListViewItem item = this.listView1.SelectedItems[0];
this.listView1.Items.Remove(item);
FileStream fs = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.Read);
int len = (int)fs.Length;
byte[] arrByte = new byte[len];
fs.Read(arrByte, 0, len);
this.textBox1.Text = Encoding.Default.GetString(arrByte);
fs.Close();
//方案2
ListViewItem item = this.listView1.SelectedItems[0];
this.listView1.Items.Remove(item);
FileStream fs = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.Read);
int len = (int)fs.Length;
byte[] arrByte = new byte[len];
int index = 0;
int code = fs.ReadByte();
while (code!=-1)
{
arrByte[index] = Convert.ToByte(code);
code = fs.ReadByte();
index++;
}
this.textBox1.Text = Encoding.Default.GetString(arrByte);
fs.Close();
//方案3
this.textBox1.Text = File.ReadAllText(this.textBox2.Text, Encoding.Default);
//方案4
FileStream fs = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.Read);
StreamReader sd = new StreamReader(fs, Encoding.Default);
this.textBox2.Text = sd.ReadToEnd();
sd.Close();
fs.Close();
ADO.NET即datareader读取数据库
添加数据第一种sqldataadapter方式:
添加数据第一种sqlcommand方式:
单窗体实现增删改查
增加
删除
修改