c#学习(7)

下面根据c#实验中遇到的问题做一下简述

第一个问题

存储文件

private static void SaveFile(string filename, RichTextBox richTextBox)
{
if (string.IsNullOrEmpty(filename))
{
throw new ArgumentNullException();
}
using (System.IO.FileStream stream = System.IO.File.OpenWrite(filename))
{
TextRange documentTextRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
string dataFormat = DataFormats.Text;
string ext = System.IO.Path.GetExtension(filename);
if (String.Compare(ext, ".xaml", true) == 0)
{
dataFormat = DataFormats.Xaml;
}
else if (String.Compare(ext, ".rtf", true) == 0)
{
dataFormat = DataFormats.Rtf;
}
documentTextRange.Save(stream, dataFormat);
}
}

2播放音乐

SoundPlayer msc = new SoundPlayer("c//music.wav");
msc.Play();

 

posted on 2015-05-04 09:59  石家名  阅读(121)  评论(0编辑  收藏  举报