首页 字体选择打开和保存文件的代码

字体选择打开和保存文件的代码

举报
开通vip

字体选择打开和保存文件的代码字体选择打开和保存文件的代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; System.Windows.Forms; using using System.IO; namespace WordForm { public partial class Form1 : Fo...

字体选择打开和保存文件的代码
字体选择打开和保存文件的代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; System.Windows.Forms; using using System.IO; namespace WordForm { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnFont_Click(object sender, EventArgs e) { FontDialog fd = new FontDialog(); fd.ShowColor = true; fd.ShowApply = true; fd.Apply += new EventHandler(fd_Apply); fd.ShowHelp = true; if (fd.ShowDialog() == DialogResult.OK) { tbEdit.Font = fd.Font; tbEdit.ForeColor = fd.Color; } } void fd_Apply(object sender, EventArgs e) { FontDialog fd = sender as FontDialog; tbEdit.Font = fd.Font; tbEdit.ForeColor = fd.Color; } private void btnColor_Click(object sender, EventArgs e) { ColorDialog cd = new ColorDialog(); cd.CustomColors = new int[3] { 1647214, 1425785, 1647258 }; if (cd.ShowDialog() == DialogResult.OK) { tbEdit.BackColor = cd.Color; } } private void btnFolderBrower_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.SelectedPath = "c:\\"; fbd.ShowNewFolderButton = true; fbd.ShowNewFolderButton = true; fbd.Description = "请选择目录"; if (fbd.ShowDialog() == DialogResult.OK) { tbEdit.Text = fbd.SelectedPath; } } private void btnOpenFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = "c:\\"; ofd.Filter = "Text.Document(*.text)|*.text|All Files(*.*)|*.*"; ofd.FilterIndex = 1; if(ofd.ShowDialog()==DialogResult.OK) { if (ofd.FileName != "") { ReadFile(ofd.FileName); } } } private void ReadFile(String fileName) { try { StreamReader sr = new StreamReader(fileName); tbEdit.Text = sr.ReadToEnd(); sr.Close(); } catch(IOException err) { MessageBox.Show(err.Message); } } private void btnSaveFile_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); ; sfd.AddExtension = true sfd.DefaultExt = "txt"; sfd.Filter = "Text Document(*.txt)|*.txt|All Files(*.*)|*.*"; sfd.CheckFileExists = true; sfd.CheckPathExists = true; if (sfd.ShowDialog() == DialogResult.OK) { if (sfd.FileName != "") { WriteToFile(sfd.FileName); } } } private void WriteToFile(string fileName) { try { FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(tbEdit.Text); sw.Close(); sw.Close(); } catch(IOException err) { MessageBox.Show(err.Message ); } } } }
本文档为【字体选择打开和保存文件的代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_266065
暂无简介~
格式:doc
大小:18KB
软件:Word
页数:0
分类:企业经营
上传时间:2017-12-09
浏览量:79