一、消息弹窗
1.窗体跳转
OrderForms of = new OrderForms();//new出新的窗体对象
this.Hide(); //隐藏当前窗体
of.ShowDialog(); //打开窗体
of.Show(); //打开隐藏的窗体
二、IO文件操作
例:通过路径读取活写入文本文件,显示到窗体中,复制按钮为复制一个视频案例。
private void btnWrite_Click(object sender, EventArgs e)//写入
{
string path = tbPath.Text.Trim();
FileStream fs = new FileStream(path,FileMode.Create,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write(tbDate.Text);
sw.Close();
fs.Close();
tbDate.Text = "";
MessageBox.Show("写入成功");
}
private void btnRead_Click(object sender, EventArgs e)//读取
{
string path = tbPath.Text.Trim();
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
tbDate.Text=sr.ReadToEnd();
sr.Close();
fs.Close();
}
private void btnCopy_Click(object sender, EventArgs e)//复制
{
string path1 = "G:\\南山景区3D导游员.mp4"; //原始路径
string path2 = @"G:\大片\成果.mp4"; //复制后的路径
using (FileStream fReader = new FileStream(path1, FileMode.Open, FileAccess.Read))//只在using范围内有效
{
using (FileStream fWrite = new FileStream(path2, FileMode.Create, FileAccess.Write))
{
byte[] date = new byte[1024*1024*10];//10M
int r = fReader.Read(date,0,date.Length);//r为每次读多少
while (r>0)//通过r大小判断是否读取完成
{
fWrite.Write(date,0,r);//写入文件
r = fReader.Read(date,0,date.Length);//继续读取,读完为止
}
MessageBox.Show("复制完成,快去欣赏吧!");
}
}
}