对话框:  注意引用using System.IO;
showdialog();显示对话框,返回一个dialogresult的枚举类型

colorDialog:color属性,用来获取颜色
folderBrowserDialog:SelectedPath选中路径
fontDialog:font属性,返回一个font类型的值,里面存储了关于字体的设置
openFileDialog:
filename获取或设置文件路径包含文件名
filenames 是文件路径字符串数组
filter:文件筛选器 格式为 提示文本一|*.后缀|提示文本二|*.后缀|提示文本三|*.后缀
saveFileDialog1:
filename获取或设置文件路径包含文件名
filenames 是文件路径字符串数组
filter:文件筛选器 格式为 提示文本一|*.后缀|提示文本二|*.后缀|提示文本三|*.后缀

 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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//颜色
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = colorDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
this.BackColor = colorDialog1.Color;
}
}
//文件夹浏览器
private void button2_Click(object sender, EventArgs e)
{
DialogResult dr = folderBrowserDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
MessageBox.Show(folderBrowserDialog1.SelectedPath);
}
else
{
MessageBox.Show(folderBrowserDialog1.SelectedPath);
}
}
//字体
private void button3_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
MessageBox.Show(fontDialog1.Font.Size.ToString());
}
//打开
private string Files;
private void button4_Click(object sender, EventArgs e)
{
DialogResult dr = openFileDialog1.ShowDialog();
if (DialogResult.OK == dr)
{
string filename = openFileDialog1.FileName;
StreamReader sr = new StreamReader(filename);
textBox1.Text = sr.ReadToEnd();
sr.Close(); Files = filename;
}
}
//保存
private void button5_Click(object sender, EventArgs e)
{
if (Files == null)
{
saveFileDialog1.Filter = "文本 |*.txt|word|*.doc|excel|*.xls";
DialogResult dr = saveFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
string filename = saveFileDialog1.FileName; StreamWriter sw = new StreamWriter(filename);
sw.Write(textBox1.Text);
sw.Close();
}
}
else
{
StreamWriter sw = new StreamWriter(Files);
sw.Write(textBox1.Text);
sw.Close();
}
} private void Form1_Load(object sender, EventArgs e)
{ }
//关闭窗体
private void button6_Click(object sender, EventArgs e)
{
this.Close();
}
//页面设置
private void button7_Click(object sender, EventArgs e)
{
pageSetupDialog1.Document = printDocument1;
pageSetupDialog1.ShowDialog();
}
//打印
private void button8_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
DialogResult dr = printDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
printDocument1.Print();
}
} private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
System.Drawing.Font f = new System.Drawing.Font("宋体",);
e.Graphics.DrawString(textBox1.Text,f,System.Drawing.Brushes.Aqua,,);
}
}
}

流:
输入流:

string filename = openFileDialog1.FileName;
//通过读入流进行文件读取
StreamReader sr = new StreamReader(filename);
textBox1.Text = sr.ReadToEnd();
sr.Close();

输出流:

string filename = saveFileDialog1.FileName;
//写入流,可以在硬盘上创建文件,并为文件写入信息
StreamWriter sw = new StreamWriter(filename);
sw.Write(this.textBox1.Text);
sw.Close();
this:代表的它所在的那个类当前对象

 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 FirstForm
{
public partial class JiShiben : Form
{
public JiShiben()
{
InitializeComponent();
} private void textBox1_TextChanged(object sender, EventArgs e)
{
//MessageBox.Show("你好");
if (this.textBox1.Text.Length > )
{
撤销ToolStripMenuItem.Enabled = true;
}
} private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Copy();
} private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Paste();
} private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Cut();
} private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.CanUndo == true)
{
// Undo the last operation.
textBox1.Undo();
// Clear the undo buffer to prevent last action from being redone.
textBox1.ClearUndo();
}
} private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectedText = "";
} private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectAll();
} private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult dr = openFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
string filename = openFileDialog1.FileName;
//通过读入流进行文件读取
StreamReader sr = new StreamReader(filename);
textBox1.Text = sr.ReadToEnd();
sr.Close();
}
} private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length > )
{
DialogResult drg= MessageBox.Show("是否进行保存?","保存对话框",MessageBoxButtons.YesNo);
if (DialogResult.Yes == drg)
{
if (FileName == null)
{
DialogResult dr = saveFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;
//写入流,可以在硬盘上创建文件,并为文件写入信息
StreamWriter sw = new StreamWriter(filename);
sw.Write(this.textBox1.Text);
sw.Close();
}
}
else
{
//写入流,可以在硬盘上创建文件,并为文件写入信息
StreamWriter sw = new StreamWriter(FileName);
sw.Write(this.textBox1.Text);
sw.Close();
}
}
} FileName = null;
this.textBox1.Text = "";
}
private string FileName;
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FileName == null)
{
DialogResult dr = saveFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;
//写入流,可以在硬盘上创建文件,并为文件写入信息
StreamWriter sw = new StreamWriter(filename);
sw.Write(this.textBox1.Text);
sw.Close();
}
}
else
{
//写入流,可以在硬盘上创建文件,并为文件写入信息
StreamWriter sw = new StreamWriter(FileName);
sw.Write(this.textBox1.Text);
sw.Close();
}
} private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "文本文件(*.txt)|*.txt|word文件(*.doc)|*.doc";
DialogResult dr = saveFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;
//写入流,可以在硬盘上创建文件,并为文件写入信息
StreamWriter sw = new StreamWriter(filename);
sw.Write(this.textBox1.Text);
sw.Close();
}
} private void 页面设置ToolStripMenuItem_Click(object sender, EventArgs e)
{
pageSetupDialog1.Document = printDocument1;//为页面设置对话框指定打印对象
pageSetupDialog1.ShowDialog();//打开页面对话框
} private void 打印ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult dr = printDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
printDocument1.Print();
}
} private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//设置打印的画板内容
System.Drawing.Font f = new System.Drawing.Font("宋体", );
e.Graphics.DrawString(this.textBox1.Text, f, SystemBrushes.ActiveBorder, 10.0f, 0f);
} private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
{
//Find ff = new Find(this.textBox1.SelectedText,this);
//ff.Owner = this;
//ff.Show();
} private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
} private void JiShiben_Load(object sender, EventArgs e)
{ }
}
}

打印:
打印对话框:printdialog
页面设置:pagesetupdialog
这两个对话框都需要通过设置printdocument来指定打印对象
printdocument:打印对象,必须要有,一块画板,用于打印机与打印内容之间中转,打印机打印的是printdoment
printDocument1_PrintPage:事件,每打印一页之前触发,用于给printdocument指定打印内容
通过画板把内容画到打印对象的页上:
System.Drawing.Font f = new System.Drawing.Font("宋体",12);
e.Graphics.DrawString(textBox1.Text,f,System.Drawing.Brushes.Aqua,5,5);
最后打印: 打印对话框那,如果打印对话框返回确定打印,就执行printdocument.print();

winform —— 对话框和流及打印的更多相关文章

  1. winform对话框控件、打印控件

    对话框控件: ColorDialog:颜色选择对话框,让用户自行选择一种颜色,使用方法类似FontDialog FontDialog:字体选择对话框,让用户自行选择一种字体(也可以选择字体颜色,需要在 ...

  2. winform 对话框控件,打印控件

    1.文件对话框(FileDialog) 它又常用到两个: 打开文件对话框(OpenFileDialog) 保存文件对话框(SaveFileDialog) 2.字体对话框(FontDialog) 3.颜 ...

  3. C#窗体 WinForm 对话框,流

    一.对话框 ColorDialog:颜色选择控件 private void button1_Click(object sender, EventArgs e) { //显示颜色选择器 colorDia ...

  4. WinForm 对话框、流

    一.对话框 ColorDialog:颜色选择控件 private void button1_Click(object sender, EventArgs e) { //显示颜色选择器 colorDia ...

  5. WinForm 对话框,流

    private void button1_Click(object sender, EventArgs e) { //显示颜色选择器 colorDialog1.ShowDialog(); //把取到的 ...

  6. winform 对话框、打印框

    winform 对话框控件 1.打开文件对话框(OpenFileDialog) 2.保存文件对话框(SaveFileDialog) 3.字体对话框(FontDialog) 4.颜色对话框(ColorD ...

  7. WinForm对话框

    WinForm 对话框控件colorDialog - 颜色选择对话框 使用代码如下: private void 字体颜色ToolStripMenuItem_Click(object sender, E ...

  8. java 21 - 12 IO流的打印流

    打印流 字节流打印流 PrintStream 字符打印流 PrintWriter打印流的特点: A:只有写数据的,没有读取数据.只能操作目的地,不能操作数据源.(只能写入数据到文件中,而不能从文件中提 ...

  9. 我爱Java系列之《JavaEE学习笔记day12》---【缓冲流、转换流、序列/反序列化流、打印流】

    [缓冲流.转换流.序列/反序列化流.打印流] 一.缓冲流 1.字节缓冲输出流 java.io.BufferedOutputStream extends OutputStream 高效字节输出流 写入文 ...

随机推荐

  1. nodejs 批处理运行 app.js

    1.直接执行run.bat文件         以下的内容为批处理文件run.bat中的内容,批处理命令中NODE_PATH为Node.js的安装路径. 使用express 生成的项目.app.js为 ...

  2. VS2008快捷键_大全

    Ctrl+B,C: 清除全部标签 Ctrl+I: 渐进式搜索 Ctrl+Shift+I: 反向渐进式搜索 Ctrl+F: 查找 Ctrl+Shift+F: 在文件中查找 F3: 查找下一个 Shift ...

  3. Git 多人协作的工作模式

    多人协作 148次阅读 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git rem ...

  4. java获取当前系统毫秒,纳秒

    //获取当前系统毫秒 System.out.println(System.currentTimeMillis()); //获取当前系统纳秒 System.out.println(System.nano ...

  5. linux下查看文件及目录个数

    linux下查看文件及目录个数1.查看当前文件和目录总数(不包括子目录):ls -l | wc -l 2.查看当前目录下文件个数(不包括子目录):ls -l |grep "^-"| ...

  6. 面试总结之html+css

    最近面试了一些公司,和技术总监聊了一些前端技术方面的内容.回来之后我总结了一下,大致可以分为三个模块:第一.Html与css 方面:第二.浏览器解析方面:第三.js方面.打算,分为三篇博文,根据自己的 ...

  7. React-Native OpenGL体验一

    昨天初体验了一把SVG一个并不是多么复杂的动画,我在iOS模拟器上体验的是流畅的,但是在Android真机上体验,还是比较卡的. 下面来介绍一个OpenGL的第三方库: 下面是我运行的里面Demo的效 ...

  8. KVC与KVO的理解

    KVC与KVO是Objective C的关键概念. Key—Value Coding (KVC) 即是指NSKeyValueCoding,一个非正式的Protocol,提供一种机制间接访问对象的属性. ...

  9. Linux中Firefox——Firebug插件安装及使用

    Firebug的安装方法即打开方式同httpfox Firebug使用指南: Firebug可以随时编辑页面:在HTML标签中,点击窗口上方的"inspect"命令,然后再选择页面 ...

  10. JavaScript数组知识网络

    JavaScript数据类型 基本数据类型 Boolean Null Number String Symbol Undefined 对象数据类型Object Build-in object Array ...