http://developer.ccidnet.com/pub/disp/Article?columnID=322&articleID=11253&pageNO=1
选择文件对话框
//定义一个"打开文件对话框"
OpenFileDialog openFileDialog1 = new OpenFileDialog ( ) ;
//定义此对话框的初始化目录
openFileDialog1.InitialDirectory = "c://" ;
//定义此对话框文件过滤类型
openFileDialog1.Filter= "txt files(*.txt)|*.txt|All files (*.*)|*.*" ;
//此对话框缺省过滤类型为第二个
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if ( openFileDialog1.ShowDialog ( ) == DialogResult.OK )
{
fName = openFileDialog1.FileName ;
showInfo ( ) ;
sr = new StreamReader ( fName ) ;
}
选择字体对话框
FontDialog fontDialog1 = new FontDialog ( ) ;
fontDialog1.ShowColor = true ;
fontDialog1.AllowScriptChange = false ;
if ( fontDialog1.ShowDialog ( ) != DialogResult.Cancel )
{
fnt = fontDialog1.Font ;
showInfo ( ) ;
}
颜色选择对话框
ColorDialog ColorDialog1 = new ColorDialog ( ) ;
ColorDialog1.AllowFullOpen = true ;
ColorDialog1.FullOpen = true ;
//设定此颜色对话框存在"帮助"按钮,缺省是没有的
ColorDialog1.ShowHelp = true ;
// 设定此颜色对话框的初始颜色,所以如果在对话框中选择"取消",则此对话框会重新此颜色
ColorDialog1.Color = Color.DarkBlue ;
if ( ColorDialog1.ShowDialog ( ) != DialogResult.Cancel )
{
clr = ColorDialog1.Color ;
showInfo ( ) ;
}
保存文件对话框
Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog ( ) ;
saveFileDialog1.Filter= " txt files(*.txt)|*.txt|All files(*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
if ( saveFileDialog1.ShowDialog ( ) == DialogResult.OK )
{
if ( ( myStream = saveFileDialog1.OpenFile ( ) ) != null )
{
//设定"sr"对象的指针指向读取文件流的开始位置
sr.BaseStream.Seek ( 0 , SeekOrigin.Begin ) ;
int i ;
//判断"sr"中的指针是否指向文件流的结尾位置
while ( ( i = sr.BaseStream.ReadByte ( ) ) != -1 )
{
//不断的往文件中写入字节
myStream.WriteByte ( ( byte ) i ) ;
}
myStream.Close ( ) ;
sr.BaseStream.Seek ( 0 , SeekOrigin.Begin ) ;
}
}
设置打印机对话框
//创建一个设置打印机对话框对象
PrintDialog PrintDialog1 = new PrintDialog ( ) ;
//首先要新建一个打印文档,
pd = new PrintDocument ( ) ;
PrintDialog1.ShowNetwork=false;
PrintDialog1.PrintToFile = false ;
PrintDialog1.Document = pd ;
if ( PrintDialog1.ShowDialog ( ) != DialogResult.Cancel )
{
try
{
pd.Print ( ) ;
}
catch ( Exception ex )
{
MessageBox.Show ( ex.Message ) ;
}
}
打印预览对话框
//创建一个打印文档
pd = new PrintDocument ( ) ;
//创建一个打印预览对话框对象
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog ( ) ;
printPreviewDialog1.Document = this.pd ;
printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D ;
printPreviewDialog1.ShowDialog ( ) ;