博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Chapter 7. 对话框控件
阅读量:6942 次
发布时间:2019-06-27

本文共 3286 字,大约阅读时间需要 10 分钟。

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace 对话框控件{    public partial class Form2 : Form    {        public Form2()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            SaveFileDialog sfd = new SaveFileDialog();            sfd.Title = "请选择要保存的路径";            sfd.InitialDirectory = @"C:\Users\Administrator\Desktop";            sfd.Filter = "文本文件|*.txt|所有文件|*.*";            sfd.ShowDialog();            //获得保存文件的路径            string path = sfd.FileName;            if(path == "")            {                return;            }            using (FileStream fsWrite = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))            {                byte[] buffer = Encoding.Default.GetBytes(textBox1.Text);                fsWrite.Write(buffer,0,buffer.Length);            }            MessageBox.Show("保存成功");        }    }}

 

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace 对话框控件{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            //点击弹出对话框            OpenFileDialog ofd = new OpenFileDialog();                        //设置对话框的标题            ofd.Title = "请选择要打开的文本文件";            //设置对话框可以多选            ofd.Multiselect = true;            //设置对话框的初始目录            ofd.InitialDirectory = @"C:\Users\Administrator\Desktop";            //设置打开文件的类型            ofd.Filter = "文本文件|*.txt |图片文件|*.jpg |所有文件|*.*";            //展示对话框            ofd.ShowDialog();            //获得在打开对话框中选中文件的路径            string path = ofd.FileName;            if (path == "")            {                return;            }            using(FileStream fsRead = new FileStream(path,FileMode.OpenOrCreate,FileAccess.Read))            {                byte[] buffer = new byte[1024*1024*5];                //实际读取到的字节数                int r = fsRead.Read(buffer,0,buffer.Length);                textBox1.Text = Encoding.Default.GetString(buffer,0,r);            }        }    }}

 

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 对话框控件{    public partial class Form3 : Form    {        public Form3()        {            InitializeComponent();        }        ///         /// 字体对话框        ///         ///         ///         private void button1_Click(object sender, EventArgs e)        {                        FontDialog fd = new FontDialog();            fd.ShowDialog();            textBox1.Font = fd.Font;        }        ///         /// 颜色对话框        ///         ///         ///         private void button2_Click(object sender, EventArgs e)        {            ColorDialog cd = new ColorDialog();            cd.ShowDialog();            textBox1.ForeColor = cd.Color;        }    }}

 

 

转载于:https://www.cnblogs.com/xiao55/p/5642180.html

你可能感兴趣的文章
Java中的异常处理
查看>>
深入理解ES6之《块级作用域绑定》
查看>>
Solution - 收藏集 - 掘金
查看>>
分享一个可用于拖动排序的vue组件
查看>>
深入解析Vue源码
查看>>
浏览器缓存机制
查看>>
【183天】黑马程序员27天视频学习笔记【Day14-上】
查看>>
2017-06-21 前端日报
查看>>
工作遇到问题的解决方案
查看>>
C学习-函数(三)
查看>>
CentOS 6安装和配置VNC(转)
查看>>
初步接触GraphQL
查看>>
ThinkPHP3.2.3 常见问题(不断更新)
查看>>
Redux概念之三: Action(动作)与Action Creator(动作创建器)
查看>>
【小玩】cc-audiobuffer 一个切片语音拼接工具
查看>>
vuejs 1.x - 实例:搜索过滤
查看>>
将PostgreSQL数据库扩展到每个月12亿条记录的经验教训
查看>>
Instana发布微服务应用程序样例
查看>>
京东Vue组件库NutUI 2.0发布:将支持跨平台!
查看>>
新书问答:Agile Management
查看>>