| ShowColor | 控制是否显示颜色选项 |
| AllowScriptChange | 是否显示字体的字符集 |
| Font | 在对话框显示的字体 |
| AllowVerticalFonts | 是否可选择垂直字体 |
| Color | 在对话框中选择的颜色 |
| FontMustExist | 当字体不存在时是否显示错误 |
| MaxSize | 可选择的最大字号 |
| MinSize | 可选择的最小字号 |
| ScriptsOnly | 显示排除OEM和Symbol字体 |
| ShowApply | 是否显示"应用"按钮 |
| ShowEffects | 是否显示下划线、删除线、字体颜色选项 |
| ShowHelp | 是否显示"帮助"按钮 |
| Apply | 当点击"应用"按钮时要处理的事件 |
| HelpRequest | 当点击"帮助"按钮时要处理的事件 |
| private void fontDialogBTN_Click(object sender, System.EventArgs e) { FontDialog fontDialog=new FontDialog(); fontDialog.Color=richTextBox1.ForeColor; fontDialog.AllowScriptChange=true; fontDialog.ShowColor=true; if(fontDialog.ShowDialog()!=DialogResult.Cancel) { richTextBox1.SelectionFont=fontDialog.Font;//将当前选定的文字改变字体 } } |
| AllowFullOpen | 禁止和启用"自定义颜色"按钮 |
| FullOpen | 是否最先显示对话框的"自定义颜色"部份 |
| ShowHelp | 是否显示"帮助"按钮 |
| Color | 在对话框中显示的颜色 |
| AnyColor | 显示可选择任何颜色 |
| CustomColors | 是否显示自定义颜色 |
| SolidColorOnly | 是否只能选择纯色 |
| private void colorDialogBTN_Click(object sender, System.EventArgs e) { ColorDialog colorDialog=new ColorDialog(); colorDialog.AllowFullOpen=true; colorDialog.FullOpen=true; colorDialog.ShowHelp=true; colorDialog.Color=Color.Black;//初始化当前文本框中的字体颜色,当用户在ColorDialog对话框中点击"取消"按钮 file://恢复原来的值 colorDialog.ShowDialog(); richTextBox1.SelectionColor=colorDialog.Color; } |
| AllowMargins | 设置是否可以对边距的编辑 |
| AllowOrientation | 是否可以使用"方向"单选框 |
| AllowPaper | 设置是否可以对纸张大小的编辑 |
| AllowPrinter | 设置是否可以使用"打印机"按钮 |
| Document | 获取打印机设置的PrintDocument |
| MinMargins | 允许用户选择的最小边距 |
| private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { float linesPerPage=0;//页面的行号 float yPos=0;//打印字符串的纵向位置 int count=0;//行计数器 float leftMargin =e.MarginBounds.Left;//左边距 float topMargin=e.MarginBounds.Top;//上边距 string line=null;//行字符串 Color clr=richTextBox1.SelectionColor;//当前的打印颜色,在我这个程序没有实现不同颜色打印 SolidBrush b =new SolidBrush(clr);//刷子 fnt=richTextBox1.SelectionFont;//当前的打印字体 linesPerPage=e.MarginBounds.Height/fnt.GetHeight(e.Graphics);//每页可打印的行数 file://逐行循行打印一页 while(count { yPos=topMargin+(count*fnt.GetHeight(e.Graphics)); e.Graphics.DrawString(line,fnt,b,leftMargin,yPos,new StringFormat()); count++; } file://如果该页打印完成而line不为空说明还有没完成的页面,发出下一次的打印事件, file://在下一次的打印中lineReader会自动读取上次没有打印完的内容。lineReader可以记录当前读取的位置 if(line!=null) e.HasMorePages=true; else e.HasMorePages=false; } |
| private void printPreviewBTN_Click(object sender, System.EventArgs e) { lineReader = new StringReader(richTextBox1.Text); try { PrintPreviewDialog printPreviewDialog1=new PrintPreviewDialog(); printPreviewDialog1.Document=printDocument; printPreviewDialog1.FormBorderStyle=FormBorderStyle.Fixed3D; printPreviewDialog1.ShowDialog(this); } catch(Exception excep) { MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } |
| AllowPrintToFile | 禁止或使用"打印到文件"复选框 |
| AllowSelection | 禁止或使用"选定内容"单选框 |
| AllowSomePages | 禁止或使用"页"单选按钮 |
| Document | 从中获取打印机设置的PrintDocument |
| PrintToFile | 打印到文件"复选框是否选中 |
| ShowHelp | 控制是否显示"帮助"按钮 |
| ShowNetWork | 控制是否显示"网络"按钮 |
| private void printDialogBTN_Click(object sender, System.EventArgs e) { PrintDialog printDialog=new PrintDialog(); printDialog.Document=printDocument; if(printDialog.ShowDialog()!=DialogResult.Cancel) { try { printDocument.Print(); } catch(Exception ex) { MessageBox.Show(ex.Message); } } } |