Form2.cs
上传用户:len11608
上传日期:2022-06-26
资源大小:21k
文件大小:6k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace abc
- {
- public partial class MdiChild : Form
- {
- public bool Textchanged = false;
- public MdiChild(MdiFather parent,string caption)
- {
- InitializeComponent();
- this.MdiParent = parent;
- this.Text = caption;
- }
- private void rtb_TextChanged(object sender, EventArgs e)
- {
- Textchanged = true;
- }
- private void MdiChild_FormClosing(object sender, FormClosingEventArgs e)
- {
- SaveFileDialog savedig = new SaveFileDialog();
- DialogResult dlgResult;
- if (Textchanged == true)
- {
- dlgResult = MessageBox.Show("文档已经被修改,保存吗?",
- "确认", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- switch (dlgResult)
- {
- case DialogResult.Yes:
- try
- {
- savedig.ShowDialog();
- rtbText.SaveFile(savedig.FileName,
- RichTextBoxStreamType.RichText);
- }
- catch (Exception)
- {
- MessageBox.Show("退出保存关闭窗体",
- "确认", MessageBoxButtons.OK);
- }
- break;
- case DialogResult.No:
- break;
- case DialogResult.Cancel:
- e.Cancel = true;
- break;
- }
- }
- }
- private void MenuClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void MenuItemT_Click(object sender, EventArgs e)
- {
- this.MdiParent.LayoutMdi(MdiLayout.TileHorizontal);
- }
- private void MenuItemV_Click(object sender, EventArgs e)
- {
- this.MdiParent.LayoutMdi(MdiLayout.TileVertical);
- }
- private void MenuSave_Click(object sender, EventArgs e)
- {
- SaveFileDialog savedig = new SaveFileDialog();
- DialogResult dlgResult;
- dlgResult = savedig.ShowDialog();
- if (dlgResult == DialogResult.OK)
- {
- rtbText.SaveFile(savedig.FileName, RichTextBoxStreamType.RichText);
- this.Text = savedig.FileName;
- Textchanged = false;
- }
- }
- private void ContextMenuColor_Click(object sender, EventArgs e)
- {
- ColorDialog colordig = new ColorDialog();
- DialogResult dlgResult;
- dlgResult = colordig.ShowDialog();
- if (dlgResult == DialogResult.OK)
- rtbText.SelectionColor = colordig.Color;
- }
- private void ContextMenuFont_Click(object sender, EventArgs e)
- {
- FontDialog fontdig = new FontDialog();
- DialogResult dlgResult;
- dlgResult = fontdig.ShowDialog();
- if (dlgResult == DialogResult.OK)
- rtbText.SelectionFont = fontdig.Font;
- }
- private void ContextMenuBold_Click(object sender, EventArgs e)
- {
- Font newfont = new Font(rtbText.SelectionFont,
- (rtbText.SelectionFont.Bold ?
- rtbText.SelectionFont.Style & ~FontStyle.Bold :
- rtbText.SelectionFont.Style | FontStyle.Bold));
- rtbText.SelectionFont = newfont;
- }
- private void ContextMenuItliac_Click(object sender, EventArgs e)
- {
- Font newfont = new Font(rtbText.SelectionFont,
- (rtbText.SelectionFont.Italic ?
- rtbText.SelectionFont.Style & ~FontStyle.Italic :
- rtbText.SelectionFont.Style | FontStyle.Italic));
- rtbText.SelectionFont = newfont;
- }
- private void ContextMenuUnderline_Click(object sender, EventArgs e)
- {
- Font newfont = new Font(rtbText.SelectionFont,
- (rtbText.SelectionFont.Underline ?
- rtbText.SelectionFont.Style & ~FontStyle.Underline :
- rtbText.SelectionFont.Style | FontStyle.Underline));
- rtbText.SelectionFont = newfont;
- }
- private void ContextMenuCut_Click(object sender, EventArgs e)
- {
- rtbText.Cut();
- }
- private void ContextMenuCopy_Click(object sender, EventArgs e)
- {
- rtbText.Copy();
- }
- private void ContextMenuPaste_Click(object sender, EventArgs e)
- {
- rtbText.Paste();
- }
- private void toolStripMenuItem2_Click(object sender, EventArgs e)
- {
- this.rtbText.ZoomFactor = 0.5f;
- }
- private void toolStripMenuItem3_Click(object sender, EventArgs e)
- {
- this.rtbText.ZoomFactor = 0.75f;
- }
- private void toolStripMenuItem4_Click(object sender, EventArgs e)
- {
- this.rtbText.ZoomFactor = 1f;
- }
- private void toolStripMenuItem5_Click(object sender, EventArgs e)
- {
- this.rtbText.ZoomFactor = 2f;
- }
- private void rtbText_LinkClicked(object sender, LinkClickedEventArgs e)
- {
- System.Diagnostics.Process.Start("IExplore", e.LinkText);
- }
- }
- }