首页 > Windows开发 > 详细

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

时间:2016-05-28 17:35:57      阅读:247      评论:0      收藏:0      [点我收藏+]
            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();

 

 

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

原文:http://www.cnblogs.com/candyzhmm/p/5537811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!