对话框:  注意引用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. Git 笔记二-Git安装与初始配置

    git 笔记二-Git安装与初始配置 Git的安装 由于我日常生活和工作基本上都是在Windows上,因此此处只说windows上的安装.Windows上的安装和其他程序一样,只需要到http://g ...

  2. 1218.3——init自定义

    相当于构造方法,有的时候初始化的时候有一些默认值,还有就是页面加载数据的时机问题,防止加载了页面再填数据 声明: -(instancetype)initWithName:(NSString *)aNa ...

  3. Ext.net GridPanel获取选中行的数据

    1.前台页面 在button中添加ExtraParams   <DirectEvents> <Click> <ExtraParams> <ext:Pramet ...

  4. VC++ 控制台不自动退出

    1.Ctrl+F5 2.结尾添加 getchar() 3.结尾添加 system("pause"); 参考:http://jingyan.baidu.com/article/555 ...

  5. 复数类(C++练习一)

    写一个复数类,实现基本的运算,目的熟悉封装与数据抽象. 类的定义 #include <iostream> #include <vector> using namespace s ...

  6. 移动web前端的一些硬技能(二)动手前必须掌握的基本常识

    记得刚开始接触移动端web的时候,书和网上的资料都不多,查起来很费劲,现在比以前要好很多了,可是还是会有一些刚接触移动端的朋友会问我一些我最初会遇到的问题,或许是书本写的并不那么重,也或许是这些知识写 ...

  7. centos源码安装git

    因为Centos上yum安装的话可能版本比较低,使用中会有一些难以预料的问题出现. 从源代码编译安装方法: #Centos执行: yum install curl-devel expat-devel ...

  8. Network Saboteur(搜索)

    Network Saboteur POJ2531 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10351   Accept ...

  9. A Distributed Multichannel MAC Protocol for Multihop Cognitive Radio Networks

    2010 这个呢,就是time slotted的DSA网络MAC层协议. 跟上一篇单纯的Multi Channel实现类似,不过这里是CR网络,因为多了嗅探等操作. 简单的说,time slotted ...

  10. 【Xamarin挖墙脚系列:Xamarin的终极破解步骤(更新)】

    前面文章中,我们可以找到对应版本的补丁. Xamarin的 4.0.1717 版本,在补丁的地址中,有作者整理的全部的安装包.迅雷磁力贴: magnet:?xt=urn:btih:9FD298AA61 ...