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();

 

 

posted @ 2016-05-28 16:45  寒夜美美  阅读(490)  评论(0编辑  收藏  举报