Chapter 7. 对话框控件
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();}/// <summary>/// 字体对话框/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button1_Click(object sender, EventArgs e){FontDialog fd = new FontDialog();fd.ShowDialog();textBox1.Font = fd.Font;}/// <summary>/// 颜色对话框/// </summary>/// <param name="sender"></param>/// <param name="e"></param>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
Chapter 7. 对话框控件相关推荐
- MFC对话框控件成员变量编程熟悉 - 开发一个简单天线长度计算器
新建一个对话框工程:VC6:VC2010类似:版本不同略有些差别: 新建完如下:对话框默认有三个控件,自己添加的: 右击 确定 按钮,建立类向导:进入类向导: Class name下拉选中对话框类:类 ...
- 目录浏览器对话框控件 c# 1614822374
目录浏览器对话框控件 c# 1614822374 引入控件 效果 显示控件 效果 显示路径 效果
- 打开文件对话框控件的演示 c# 1614993940
打开文件对话框控件的演示 c# 1614993940 引入控件 效果 显示控件 代码 效果 默认事件 文件被选中,点了打开后,触发 获取绝对路径 代码 效果 获取文件名 代码 效果 过漏获取指定格式的 ...
- android 33 对话框控件
对话框控件:最多3个按钮. mainActivity.java package com.sxt.day05_09;import android.app.Activity; import android ...
- Web开发中的弹出对话框控件介绍
Web开发中,目前由于Jquery的大行其道,因此很多弹出对话框,都用到了Jquery技术,反而原始的弹出对话框的方式较为少用了.不过基于JQuery的方式实现对话框窗口弹出,也有很多控件可以利用,由 ...
- asp.net服务器端对话框控件的简单实现(附源码)
最近项目要用到一个对话框控件,正好自己从前写了一个,拿了出来,看着自己从前写的东西,唏嘘不已. 下面是一个精简版的源代码,release在这里,谁喜欢,自己编译成dll吧. http://files. ...
- VC++开发学习三(对话框控件的绑定)
对话框的控件绑定不难,操作几遍就能掌握 对话框控件不同类型成员变量的绑定: 一个控件只能绑定控件类型和非控件类型,同时使用控件类型绑定时可以通过SetDlgItem进行设置控件的信息,GetDlgIt ...
- MFC中,如何获得对话框控件相对于父窗口(对话框窗口)的位置
在MFC中,如何获得对话框控件相对于父窗口(对话框窗口)的位置: CRect r; pWnd->GetWindowRect(&r); 这样获得的r是控件相对于屏幕的坐标,然后用Scre ...
- CAD制图教程:多跑楼梯对话框控件说明及工程实例
上一节建筑CAD制图教程中小编给大家介绍了浩辰CAD建筑软件中绘制多跑楼梯的相关操作技巧,为了让各位CAD制图初学入门者对此有更深入的了解,接下来的建筑CAD制图教程就让小编来给大家介绍一下国产CAD ...
最新文章
- 关于细分到字段的权限系统_操作系统中的细分
- 如何将 Linux 系统转移至 LVM 卷
- DNS(1) DNS基本概念和域名系统
- java对象的浅克隆和深克隆
- 经典:浅谈以太坊智能合约的设计模式与升级方法
- 个人工作总结05(第二阶段)
- 股票分析软件 php,哪个股票分析软件最好用?
- fgo服务器维护补偿,FGO1月23日服务器故障说明公告 全服补偿24圣晶石
- 使用Java实现word文档转图片 在线预览
- 团队合作开发常用git操作
- 小心金蝶专业版16.0后门木马勒索后门程序kissme.dll文件
- Windows环境下安装OpenCV-Python 完美解决:找不到指定模块(dll缺失)
- eNSP路由器连接外网
- maven3实战之仓库
- Lingo 简单的背包问题
- 我该如何向我的朋友解释“01背包”问题?
- npm installCould not resolve dependency:peer... 原因和解决方案
- 查找数组元素最大值和最小值(分治法)
- 怎么判断滤波器的低通、高通和带通?
- Learning to Memorize Entailment and Discourse Relations for Persona-Consistent Dialogues论文学习