




免费预览已结束,剩余4页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
效果图:包括各种功能。菜单功能快捷键右侧属性里设置。所需控件:代码: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 多文档MDI窗体实现 public partial class Form1 : Form Form2 myf = new Form2(); /定义公共变量,新建Form2对象实例 public StringReader MySReader; /字符串流对象,一行一行读取文本 public int x = 1; /记录新建子窗体个数 public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) toolStripStatusLabel2.Text = 当前日期: + DateTime.Now.ToString(); /显示当前日期时间 private void 新建NCtrlNToolStripMenuItem_Click(object sender, EventArgs e) Form2 myf = new Form2(); myf.MdiParent = this; /设置为子窗体 myf.Text = 新建文件 + x.ToString(); /设置子窗体的标题 toolStripStatusLabel1.Text = 状态:新建文档; /状态栏提示信息 x = x + 1; myf.Show(); /显示子窗体 private void 打开OCtrlOToolStripMenuItem_Click(object sender, EventArgs e) openFileDialog1.Filter = *.txt|*.txt; /设置打开对话框的文件类型 openFileDialog1.Title = 打开; /设置打开对话框的标题 if (openFileDialog1.ShowDialog() = DialogResult.OK) string strname = openFileDialog1.FileName; /提取打开文件的文件名 myf.Text = openFileDialog1.FileName; /设置子窗体的文件名 myf.richTextBox1.Clear(); myf.richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);/打开文件 myf.MdiParent = this; /设置窗体为子窗体 myf.Show(); /显示子窗体 toolStripStatusLabel1.Text = toolStripStatusLabel1.Text + 打开文件;/状态栏提示信息 private void 保存SCtrlSToolStripMenuItem_Click(object sender, EventArgs e) saveFileDialog1.Filter = 文本文档(*.txt|*.txt); /设置保存对话框类型 saveFileDialog1.FilterIndex = 2; if (saveFileDialog1.ShowDialog() = DialogResult.OK) /保存文件 myf.richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText); private void 页面设置ToolStripMenuItem_Click(object sender, EventArgs e) pageSetupDialog1.Document = this.printDocument1; /页面设置内容 pageSetupDialog1.ShowDialog(); /页面设置对话框 private void 打印预览PToolStripMenuItem_Click(object sender, EventArgs e) printPreviewDialog1.Document = printDocument1; MySReader = new StringReader(myf.richTextBox1.Text);/打印预览内容 try printPreviewDialog1.ShowDialog(); /打印预览对话框 catch printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs(); private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) Graphics frmGraphics = e.Graphics; Font frmFont = myf.richTextBox1.Font; /设置字体类型 float intpage = e.MarginBounds.Height; /每一页的行数 frmFont.GetHeight(frmGraphics); int intPratn = 0; /打印的行数计数 float fYposition = 0; /打印时的纵坐标 float fLeft = e.MarginBounds.Left; float fTop = e.MarginBounds.Top; string strfrmling = ; while (intPratn intpage) & (strfrmling = MySReader.ReadLine() != null) fYposition = fTop + intPratn * frmFont.GetHeight(frmGraphics); frmGraphics.DrawString(strfrmling, frmFont, new SolidBrush(Color.Black), fLeft, fYposition, new StringFormat(); intPratn+; if (strfrmling != null) e.HasMorePages = true; /没打印完发出下一页打印事情 else e.HasMorePages = false; private void 退出QToolStripMenuItem_Click(object sender, EventArgs e) this.Close(); Application.Exit(); private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e) int CutInt = myf.richTextBox1.SelectionStart; Clipboard.SetDataObject(myf.richTextBox1.SelectedText); myf.richTextBox1.Text = myf.richTextBox1.Text.Substring(0, CutInt) + myf.richTextBox1.Text.Substring(CutInt, myf.richTextBox1.SelectedText.Length); myf.richTextBox1.SelectionStart = CutInt; private void 复制CToolStripMenuItem_Click(object sender, EventArgs e) Clipboard.SetDataObject(myf.richTextBox1.SelectedText); /复制选择文本 private void 粘贴VToolStripMenuItem_Click(object sender, EventArgs e) IDataObject idat = Clipboard.GetDataObject(); if (idat.GetDataPresent(DataFormats.Text) string PasteStr = (string)idat.GetData(DataFormats.Text); int pasteid = myf.richTextBox1.SelectionStart; myf.richTextBox1.Text = myf.richTextBox1.Text.Substring(0, pasteid) + PasteStr + myf.richTextBox1.Text.Substring(pasteid); myf.richTextBox1.SelectionStart = pasteid + PasteStr.Length; private void 全选AToolStripMenuItem_Click(object sender, EventArgs e) myf.richTextBox1.SelectAll(); /全选文本 private void 字体FToolStripMenuItem_Click(object sender, EventArgs e) fontDialog1.ShowDialog(); /字体对话框 fontDialog1.AllowVerticalFonts = true; fontDialog1.FixedPitchOnly = true; fontDialog1.ShowApply = true; fontDialog1.ShowEffects = true; if (myf.richTextBox1.SelectedText = ) myf.richTextBox1.Font = fontDialog1.Font; /设置所有文字字体属性 else myf.richTextBox1.SelectionFont = fontDialog1.Font;/设置所选的文字字体属性 private void 层叠AToolStripMenuItem_Click(object sender, EventArgs e) this.LayoutMdi(MdiLayout.Cascade); private void 横向平铺FToolStripMenuItem_Click(object sender, EventArgs e) this.LayoutMdi(Md
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 救援技师考试题库及答案
- 电工考试的实操电路题及答案
- 国际组织视角下的兽药残留风险分析与管理策略探究
- 全国教师笔试试题及答案
- 2025年自考审计学试题及答案
- 2025年保护环境知识竞赛题库及答案
- 青岛市幼师考编笔试题及答案
- 青岛地铁招聘笔试题库及答案
- 前端面试笔试题及答案
- 2025年岗位模拟主管护师考试试题及答案
- 南昌大学 2018-2019学年第二学期期中考试大学英语试卷
- 2025-2030酒吧行业市场发展分析及投资前景研究报告
- 预防阿尔茨海默症
- 2025-2030中国妇科中成药市场营销趋势及投融资发展状况研究报告
- 艾滋病防治知识宣传
- 危重患者肠内营养的护理
- 主题班会:养成教育
- 2024年全国职业院校技能大赛高职组(建筑工程识图赛项)考试题库(含答案)
- 《简单相信傻傻坚持》课件-中职语文高二同步课件(高教版2023职业模块)
- 人身安全主题课件
- 《中国象棋基础教程》课件
评论
0/150
提交评论