对话框:  注意引用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. IOS总结_无需自己定义UITabbar也可改变UITabbarController的背景和点击和的颜色

    在application: application didFinishLaunchingWithOptions: launchOptions 增加以下代码就能够实现对tabbar的颜色的改动 //设定 ...

  2. 前端编辑神器Brackets

    介绍 Brackets 是Adobe发布的一款免费.开源且跨平台的 HTML/CSS/JavaScript 前端 WEB 集成开发环境.使用Node.js构建!官网:http://brackets.i ...

  3. IoC容器Autofac之IOC/DI基本概念(二)

    原文:http://www.cnblogs.com/xdp-gacl/p/4249939.html 1.1.IoC是什么 Ioc—Inversion of Control,即“控制反转”,一种设计思想 ...

  4. 是什么让我想到开发NFinal

    我是从01前开始就接触.net,那时.net还是1.0时代,很多东西都没有.后来.net出了2.0版本.从vs2005开始就使用Webform做网站.当时感觉.net能够拖来拖去,很厉害.参加工作后, ...

  5. hbase权威指南学习笔记--过滤器

    1.使用hbase是shell客户端进行过滤查询 scan 'testtable',{COLUMNS=>'colfam1:col-0',FILTER=>RowFilter.new(Comp ...

  6. cocos2d-x 2.2.6中c++通过JNI与java互调

    1.HelloCpp.java /**************************************************************************** Copyri ...

  7. 使用 Require.js 引用第三方框架时遇到的一些情况

    使用 Require.js 引用第三方框架时遇到的一些情况 在使用Require.js解析依赖的时候,会出现以下几种情况: 程序中的依赖关系 当前程序 依赖于 B包, B包 依赖于 A包 A包与B包两 ...

  8. Spark IDEA开发环境构建

    本文档基于IEDA构建spark maven应用. date: 2016/8/1 author: wangxl 1.下载IDEA https://www.jetbrains.com/idea/ 2.安 ...

  9. (原)Microsoft Source Reader的简单使用

    感觉Microsoft Source Reader还是比较坑的,只是由于需要,不得不使用.其实按照Microsoft提供的示例,基本上可以正常的调试出程序来. 下面的例子,简单的给出了Source R ...

  10. hibernate中.hbm.xml和注解方式自动生成数据表的简单实例(由新手小白编写,仅适用新手小白)

    绝逼新手小白,so 请大神指点! 如果真的错的太多,错的太离谱,错的误导了其他小伙伴,还望大神请勿喷,大神请担待,大神请高抬贵嘴......谢谢. 好了,正题 刚接触ssh,今天在搞使用.hbm.xm ...