winform学习之----打开文件对话框并将文件内容放入文本框

            OpenFileDialog ofg = new OpenFileDialog();
ofg.Title = "ddd";//设置对话框标题
ofg.Multiselect = true;//设置对话框可以多选
ofg.InitialDirectory = ;//设置对话框的初始目录
ofg.Filter = //设置文件类型
ofg.ShowDialog(); string path = ofg.FileName;
if(path == "")
{
return;
}
using(FileStream isread = new FileStream(path,FileMode.OpenOrCreate,FileAccess.Read))
{ byte[] buffer = new byte[1024*1024*5];
//设置读取到的字节数
int r = isread.Read(buffer,0,buffer.Length);
textbox1.text = Encoding.Default.GetString(buffer,0,r);
}
小知识点:

  combobox.Items.clear()
命名:cbo....
selectedindexchanged
combobox.selectitem.tostring()
comboBox1.SelectedItem.ToString().Split(new char[] { '月' }, StringSplitOptions.RemoveEmptyEntries);
listbox:直接项或者代码加项
listbox.selectedindex
listbox_doubleclick
path.GetFileName
双击播放音乐:
SoundPlayer sp = new SoundPlayer();
sp.SoundLocation = ...
sp.Play();
上一篇:老李推荐:第14章5节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-查询ViewServer运行状态


下一篇:HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632