Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Листинг П1-1. Файл ch05\SimpleNotepad\SimpleNotepadForm.cs






using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.IO;
using System.Drawing.Printing;


namespace SimpleNotepad
{
/// < summary>
/// Summary description for Form1.
/// < /summary>
public class SimpleNotepadForm: System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuFile;
private System.Windows.Forms.MenuItem menuFileNew;
private System.Windows.Forms.MenuItem menuFileOpen;
private System.Windows.Forms.MenuItem menuFileSave;
private System.Windows.Forms.MenuItem menuFileSaveAs;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuFilePageSetup;
private System.Windows.Forms.MenuItem menuFilePrint;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuFileExit;
private System.Windows.Forms.MenuItem menuEdit;
private System.Windows.Forms.MenuItem menuEditUndo;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuEditCut;
private System.Windows.Forms.MenuItem menuEditCopy;
private System.Windows.Forms.MenuItem menuEditPaste;
private System.Windows.Forms.MenuItem menuEditDelete;
private System.Windows.Forms.MenuItem menuEditSelectAll;
private System.Windows.Forms.MenuItem menuFormat;
private System.Windows.Forms.MenuItem menuFormatFont;
private System.Windows.Forms.MenuItem menuHelp;
private System.Windows.Forms.MenuItem menuHelpAbout;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.MenuItem menuFilePrintPreview;
private System.Drawing.Printing.PrintDocument printDocument1;
private System.Windows.Forms.PageSetupDialog pageSetupDialog1;
private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
private System.Windows.Forms.PrintDialog printDialog1;
private System.ComponentModel.IContainer components;

 

/// < summary>
/// StringReader для печати содержимого редактора текста
/// < /summary>
private StringReader m_myReader;

/// < summary>
/// Номер текущей распечатываемой страницы документа
/// < /summary>
private uint m_PrintPageNumber;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuFormatFontCharacterStyle;
private System.Windows.Forms.MenuItem menuFormatFontCharacterStyleBold;
private System.Windows.Forms.MenuItem menuFormatFontCharacterStyleItalic;
private System.Windows.Forms.MenuItem menuFormatFontCharacterStyleUnderline;
private System.Windows.Forms.MenuItem menuFormatFontParagraphAlignment;
private System.Windows.Forms.MenuItem menuFormatFontParagraphAlignmentLeft;
private System.Windows.Forms.MenuItem menuFormatFontParagraphAlignmentRight;
private System.Windows.Forms.MenuItem menuFormatFontParagraphAlignmentCenter;
private System.Windows.Forms.FontDialog fontDialog1;
private System.Windows.Forms.MenuItem menuFormatColor;
private System.Windows.Forms.ColorDialog colorDialog1;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuFormatFontCharacterStyleStrikeout;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.ToolBarButton toolBarButton7;
private System.Windows.Forms.ToolBarButton toolBarButton8;
private System.Windows.Forms.ToolBarButton toolBarButton9;
private System.Windows.Forms.ToolBarButton toolBarButton10;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.MenuItem menuHelpRegister;

/// < summary>
/// Флаг изменения содержимого документа
/// < /summary>
private bool m_DocumentChanged = false;


public SimpleNotepadForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
m_PrintPageNumber = 1;
}

/// < summary>
/// Clean up any resources being used.
/// < /summary>
protected override void Dispose(bool disposing)
{
if(disposing)
{
if (components! = null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code
/// < summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// < /summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SimpleNotepadForm));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuFile = new System.Windows.Forms.MenuItem();
this.menuFileNew = new System.Windows.Forms.MenuItem();
this.menuFileOpen = new System.Windows.Forms.MenuItem();
this.menuFileSave = new System.Windows.Forms.MenuItem();
this.menuFileSaveAs = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuFilePageSetup = new System.Windows.Forms.MenuItem();
this.menuFilePrintPreview = new System.Windows.Forms.MenuItem();
this.menuFilePrint = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuFileExit = new System.Windows.Forms.MenuItem();
this.menuEdit = new System.Windows.Forms.MenuItem();
this.menuEditUndo = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuEditCut = new System.Windows.Forms.MenuItem();
this.menuEditCopy = new System.Windows.Forms.MenuItem();
this.menuEditPaste = new System.Windows.Forms.MenuItem();
this.menuEditDelete = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuEditSelectAll = new System.Windows.Forms.MenuItem();
this.menuFormat = new System.Windows.Forms.MenuItem();
this.menuFormatFont = new System.Windows.Forms.MenuItem();
this.menuFormatColor = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuFormatFontCharacterStyle = new System.Windows.Forms.MenuItem();
this.menuFormatFontCharacterStyleBold = new System.Windows.Forms.MenuItem();
this.menuFormatFontCharacterStyleItalic = new System.Windows.Forms.MenuItem();
this.menuFormatFontCharacterStyleUnderline = new System.Windows.Forms.MenuItem();
this.menuFormatFontCharacterStyleStrikeout = new System.Windows.Forms.MenuItem();
this.menuFormatFontParagraphAlignment = new System.Windows.Forms.MenuItem();
this.menuFormatFontParagraphAlignmentLeft = new System.Windows.Forms.MenuItem();
this.menuFormatFontParagraphAlignmentRight = new System.Windows.Forms.MenuItem();
this.menuFormatFontParagraphAlignmentCenter = new System.Windows.Forms.MenuItem();
this.menuHelp = new System.Windows.Forms.MenuItem();
this.menuHelpAbout = new System.Windows.Forms.MenuItem();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
this.printDialog1 = new System.Windows.Forms.PrintDialog();
this.fontDialog1 = new System.Windows.Forms.FontDialog();
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton7 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton9 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton10 = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.menuHelpRegister = new System.Windows.Forms.MenuItem();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]
{
this.menuFile,
this.menuEdit,
this.menuFormat,
this.menuHelp});
//
// menuFile
//
this.menuFile.Index = 0;
this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFileNew,
this.menuFileOpen,
this.menuFileSave,
this.menuFileSaveAs,
this.menuItem3,
this.menuFilePageSetup,
this.menuFilePrintPreview,
this.menuFilePrint,
this.menuItem6,
this.menuFileExit});
this.menuFile.Text = " & File";
this.menuFile.Select += new System.EventHandler(this.MenuSelect);
//
// menuFileNew
//
this.menuFileNew.Index = 0;
this.menuFileNew.Text = " & New";
this.menuFileNew.Click += new System.EventHandler(this.menuFileNew_Click);
this.menuFileNew.Select += new System.EventHandler(this.MenuSelect);
//
// menuFileOpen
//
this.menuFileOpen.Index = 1;
this.menuFileOpen.Text = " & Open...";
this.menuFileOpen.Click += new System.EventHandler(this.menuFileOpen_Click);
this.menuFileOpen.Select += new System.EventHandler(this.MenuSelect);
//
// menuFileSave
//
this.menuFileSave.Index = 2;
this.menuFileSave.Text = " & Save";
this.menuFileSave.Click += new System.EventHandler(this.menuFileSave_Click);
this.menuFileSave.Select += new System.EventHandler(this.MenuSelect);
//
// menuFileSaveAs
//
this.menuFileSaveAs.Index = 3;
this.menuFileSaveAs.Text = " & Save As...";
this.menuFileSaveAs.Click += new System.EventHandler(this.menuFileSaveAs_Click);
this.menuFileSaveAs.Select += new System.EventHandler(this.MenuSelect);
//
// menuItem3
//
this.menuItem3.Index = 4;
this.menuItem3.Text = " -";
//
// menuFilePageSetup
//
this.menuFilePageSetup.Index = 5;
this.menuFilePageSetup.Text = " Page Set& up...";
this.menuFilePageSetup.Click += new System.EventHandler(this.menuFilePageSetup_Click);
this.menuFilePageSetup.Select += new System.EventHandler(this.MenuSelect);
//
// menuFilePrintPreview
//
this.menuFilePrintPreview.Index = 6;
this.menuFilePrintPreview.Text = " Print Pre& view...";
this.menuFilePrintPreview.Click += new System.EventHandler(this.menuFilePrintPreview_Click);
this.menuFilePrintPreview.Select += new System.EventHandler(this.MenuSelect);
//
// menuFilePrint
//
this.menuFilePrint.Index = 7;
this.menuFilePrint.Text = " & Print...";
this.menuFilePrint.Click += new System.EventHandler(this.menuFilePrint_Click);
this.menuFilePrint.Select += new System.EventHandler(this.MenuSelect);
//
// menuItem6
//
this.menuItem6.Index = 8;
this.menuItem6.Text = " -";
//
// menuFileExit
//
this.menuFileExit.Index = 9;
this.menuFileExit.Text = " Exit";
this.menuFileExit.Click += new System.EventHandler(this.menuFileExit_Click);
this.menuFileExit.Select += new System.EventHandler(this.MenuSelect);
//
// menuEdit
//
this.menuEdit.Index = 1;
this.menuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuEditUndo,
this.menuItem1,
this.menuItem2,
this.menuEditCut,
this.menuEditCopy,
this.menuEditPaste,
this.menuEditDelete,
this.menuItem10,
this.menuEditSelectAll});
this.menuEdit.Text = " & Edit";
this.menuEdit.Select += new System.EventHandler(this.MenuSelect);
//
// menuEditUndo
//
this.menuEditUndo.Index = 0;
this.menuEditUndo.Text = " & Undo";
this.menuEditUndo.Click += new System.EventHandler(this.menuEditUndo_Click);
this.menuEditUndo.Select += new System.EventHandler(this.MenuSelect);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = " & Redo";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
this.menuItem1.Select += new System.EventHandler(this.MenuSelect);
//
// menuItem2
//
this.menuItem2.Index = 2;
this.menuItem2.Text = " -";
//
// menuEditCut
//
this.menuEditCut.Index = 3;
this.menuEditCut.Text = " Cu& t";
this.menuEditCut.Click += new System.EventHandler(this.menuEditCut_Click);
this.menuEditCut.Select += new System.EventHandler(this.MenuSelect);
//
// menuEditCopy
//
this.menuEditCopy.Index = 4;
this.menuEditCopy.Text = " & Copy";
this.menuEditCopy.Click += new System.EventHandler(this.menuEditCopy_Click);
this.menuEditCopy.Select += new System.EventHandler(this.MenuSelect);
//
// menuEditPaste
//
this.menuEditPaste.Index = 5;
this.menuEditPaste.Text = " & Paste";
this.menuEditPaste.Click += new System.EventHandler(this.menuEditPaste_Click);
this.menuEditPaste.Select += new System.EventHandler(this.MenuSelect);
//
// menuEditDelete
//
this.menuEditDelete.Index = 6;
this.menuEditDelete.Text = " & Delete";
this.menuEditDelete.Click += new System.EventHandler(this.menuEditDelete_Click);
this.menuEditDelete.Select += new System.EventHandler(this.MenuSelect);
//
// menuItem10
//
this.menuItem10.Index = 7;
this.menuItem10.Text = " -";
//
// menuEditSelectAll
//
this.menuEditSelectAll.Index = 8;
this.menuEditSelectAll.Text = " & Select All";
this.menuEditSelectAll.Click += new System.EventHandler(this.menuEditSelectAll_Click);
this.menuEditSelectAll.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormat
//
this.menuFormat.Index = 2;
this.menuFormat.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFormatFont,
this.menuFormatColor,
this.menuItem4,
this.menuFormatFontCharacterStyle,
this.menuFormatFontParagraphAlignment});
this.menuFormat.Text = " & Format";
this.menuFormat.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFont
//
this.menuFormatFont.Index = 0;
this.menuFormatFont.Text = " & Font...";
this.menuFormatFont.Click += new System.EventHandler(this.menuFormatFont_Click);
this.menuFormatFont.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatColor
//
this.menuFormatColor.Index = 1;
this.menuFormatColor.Text = " C& olor...";
this.menuFormatColor.Click += new System.EventHandler(this.menuFormatColor_Click);
this.menuFormatColor.Select += new System.EventHandler(this.MenuSelect);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = " -";
//
// menuFormatFontCharacterStyle
//
this.menuFormatFontCharacterStyle.Index = 3;
this.menuFormatFontCharacterStyle.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFormatFontCharacterStyleBold,
this.menuFormatFontCharacterStyleItalic,
this.menuFormatFontCharacterStyleUnderline,
this.menuFormatFontCharacterStyleStrikeout});
this.menuFormatFontCharacterStyle.Text = " & Characters Style";
this.menuFormatFontCharacterStyle.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontCharacterStyleBold
//
this.menuFormatFontCharacterStyleBold.Index = 0;
this.menuFormatFontCharacterStyleBold.Text = " & Bold";
this.menuFormatFontCharacterStyleBold.Click += new System.EventHandler(this.menuFormatFontCharacterStyleBold_Click);
this.menuFormatFontCharacterStyleBold.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontCharacterStyleItalic
//
this.menuFormatFontCharacterStyleItalic.Index = 1;
this.menuFormatFontCharacterStyleItalic.Text = " & Italic";
this.menuFormatFontCharacterStyleItalic.Click += new System.EventHandler(this.menuFormatFontCharacterStyleItalic_Click);
this.menuFormatFontCharacterStyleItalic.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontCharacterStyleUnderline
//
this.menuFormatFontCharacterStyleUnderline.Index = 2;
this.menuFormatFontCharacterStyleUnderline.Text = " & Underline";
this.menuFormatFontCharacterStyleUnderline.Click += new System.EventHandler(this.menuFormatFontCharacterStyleUnderline_Click);
this.menuFormatFontCharacterStyleUnderline.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontCharacterStyleStrikeout
//
this.menuFormatFontCharacterStyleStrikeout.Index = 3;
this.menuFormatFontCharacterStyleStrikeout.Text = " & Strikeout";
this.menuFormatFontCharacterStyleStrikeout.Click += new System.EventHandler(this.menuFormatFontCharacterStyleStrikeout_Click);
this.menuFormatFontCharacterStyleStrikeout.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontParagraphAlignment
//
this.menuFormatFontParagraphAlignment.Index = 4;
this.menuFormatFontParagraphAlignment.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFormatFontParagraphAlignmentLeft,
this.menuFormatFontParagraphAlignmentRight,
this.menuFormatFontParagraphAlignmentCenter});
this.menuFormatFontParagraphAlignment.Text = " & Paragraph Alignment";
this.menuFormatFontParagraphAlignment.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontParagraphAlignmentLeft
//
this.menuFormatFontParagraphAlignmentLeft.Index = 0;
this.menuFormatFontParagraphAlignmentLeft.Text = " & Left";
this.menuFormatFontParagraphAlignmentLeft.Click += new System.EventHandler(this.menuFormatFontParagraphAlignmentLeft_Click);
this.menuFormatFontParagraphAlignmentLeft.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontParagraphAlignmentRight
//
this.menuFormatFontParagraphAlignmentRight.Index = 1;
this.menuFormatFontParagraphAlignmentRight.Text = " & Right";
this.menuFormatFontParagraphAlignmentRight.Click += new System.EventHandler(this.menuFormatFontParagraphAlignmentRight_Click);
this.menuFormatFontParagraphAlignmentRight.Select += new System.EventHandler(this.MenuSelect);
//
// menuFormatFontParagraphAlignmentCenter
//
this.menuFormatFontParagraphAlignmentCenter.Index = 2;
this.menuFormatFontParagraphAlignmentCenter.Text = " & Center";
this.menuFormatFontParagraphAlignmentCenter.Click += new System.EventHandler(this.menuFormatFontParagraphAlignmentCenter_Click);
this.menuFormatFontParagraphAlignmentCenter.Select += new System.EventHandler(this.MenuSelect);
//
// menuHelp
//
this.menuHelp.Index = 3;
this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuHelpAbout,
this.menuHelpRegister});
this.menuHelp.Text = " & Help";
this.menuHelp.Select += new System.EventHandler(this.MenuSelect);
//
// menuHelpAbout
//
this.menuHelpAbout.Index = 0;
this.menuHelpAbout.Text = " & About...";
this.menuHelpAbout.Click += new System.EventHandler(this.menuHelpAbout_Click);
this.menuHelpAbout.Select += new System.EventHandler(this.MenuSelect);
//
// openFileDialog1
//
this.openFileDialog1.Filter = " RTF files|*.rtf|Text files|*.txt|All files|*.*";
//
// richTextBox1
//
this.richTextBox1.AcceptsTab = true;
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Location = new System.Drawing.Point(0, 39);
this.richTextBox1.Name = " richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(424, 140);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = " ";
this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
//
// saveFileDialog1
//
this.saveFileDialog1.FileName = " doc1.rtf";
this.saveFileDialog1.Filter = " RTF file|*.rtf";
//
// printDocument1
//
this.printDocument1.DocumentName = " SimpleNotepad Document";
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(
this.PrintPageEventHandler);
//
// pageSetupDialog1
//
this.pageSetupDialog1.Document = this.printDocument1;
//
// printPreviewDialog1
//
this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
this.printPreviewDialog1.Document = this.printDocument1;
this.printPreviewDialog1.Enabled = true;
this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject(" printPreviewDialog1.Icon")));
this.printPreviewDialog1.Location = new System.Drawing.Point(129, 54);
this.printPreviewDialog1.MaximumSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.Name = " printPreviewDialog1";
this.printPreviewDialog1.Opacity = 1;
this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
this.printPreviewDialog1.Visible = false;
//
// printDialog1
//
this.printDialog1.Document = this.printDocument1;
//
// toolBar1
//
this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4,
this.toolBarButton5,
this.toolBarButton6,
this.toolBarButton7,
this.toolBarButton8,
this.toolBarButton9,
this.toolBarButton10});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Name = " toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(424, 39);
this.toolBar1.TabIndex = 1;
this.toolBar1.Wrappable = false;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(
this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
this.toolBarButton1.Text = " New";
this.toolBarButton1.ToolTipText = " Создание нового документа";
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.Text = " Open";
this.toolBarButton2.ToolTipText = " Открытие существующего документа";
//
// toolBarButton3
//
this.toolBarButton3.ImageIndex = 2;
this.toolBarButton3.Text = " Save";
this.toolBarButton3.ToolTipText = " Сохранение документа";
//
// toolBarButton4
//
this.toolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton5
//
this.toolBarButton5.ImageIndex = 3;
this.toolBarButton5.Text = " Cut";
this.toolBarButton5.ToolTipText = " Вырезать";
//
// toolBarButton6
//
this.toolBarButton6.ImageIndex = 4;
this.toolBarButton6.Text = " Copy";
this.toolBarButton6.ToolTipText = " Копировать";
//
// toolBarButton7
//
this.toolBarButton7.ImageIndex = 5;
this.toolBarButton7.Text = " Paste";
this.toolBarButton7.ToolTipText = " Вставить";
//
// toolBarButton8
//
this.toolBarButton8.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton9
//
this.toolBarButton9.ImageIndex = 6;
this.toolBarButton9.Text = " Preview";
this.toolBarButton9.ToolTipText = " Предварительный просмотр";
//
// toolBarButton10
//
this.toolBarButton10.ImageIndex = 7;
this.toolBarButton10.Text = " Print";
this.toolBarButton10.ToolTipText = " Печать";
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(
resources.GetObject(" imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 179);
this.statusBar1.Name = " statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(424, 22);
this.statusBar1.TabIndex = 2;
//
// statusBarPanel1
//
this.statusBarPanel1.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.statusBarPanel1.Width = 308;
//
// notifyIcon1
//
this.notifyIcon1.Text = " notifyIcon1";
this.notifyIcon1.Visible = true;
//
// menuHelpRegister
//
this.menuHelpRegister.Index = 1;
this.menuHelpRegister.Text = " & Register...";
this.menuHelpRegister.Click += new System.EventHandler(this.menuHelpRegister_Click);
//
// SimpleNotepadForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(424, 201);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.richTextBox1,
this.statusBar1,
this.toolBar1});
this.Icon = ((System.Drawing.Icon)(resources.GetObject(" $this.Icon")));
this.Menu = this.mainMenu1;
this.Name = " SimpleNotepadForm";
this.Text = " Редактор SimpleNotepad";
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// < summary>
/// The main entry point for the application.
/// < /summary>
[STAThread]
static void Main()
{
Application.Run(new SimpleNotepadForm());
}


private void menuFileNew_Click(object sender,
System.EventArgs e)
{
MenuFileNew();
}

private void menuFileOpen_Click(object sender,
System.EventArgs e)
{
MenuFileOpen();
}

private void menuFileSave_Click(object sender,
System.EventArgs e)
{
MenuFileSaveAs();
}

private void menuFileSaveAs_Click(object sender,
System.EventArgs e)
{
MenuFileSaveAs();
}

private void menuFilePageSetup_Click(object sender,
System.EventArgs e)
{
MenuFilePageSetup();
}

private void menuFilePrintPreview_Click(object sender,
System.EventArgs e)
{
MenuFilePrintPreview();
}

private void menuFilePrint_Click(object sender,
System.EventArgs e)
{
MenuFilePrint();
}

private void menuFileExit_Click(object sender,
System.EventArgs e)
{
if(m_DocumentChanged)
{
SaveDocumentNeededForm dialog = new
SaveDocumentNeededForm();
DialogResult result = dialog.ShowDialog();

switch(result)
{
case DialogResult.Yes:
{
MenuFileSaveAs();
break;
}
case DialogResult.Cancel:
{
return;
}
}
}
this.Close();
}

private void menuEditUndo_Click(object sender,
System.EventArgs e)
{
richTextBox1.Undo();
}

private void menuItem1_Click(object sender, System.EventArgs e)
{
richTextBox1.Redo();
}

private void menuEditCut_Click(object sender,
System.EventArgs e)
{
richTextBox1.Cut();
}

private void menuEditCopy_Click(object sender,
System.EventArgs e)
{
richTextBox1.Copy();
}

private void menuEditPaste_Click(object sender,
System.EventArgs e)
{
richTextBox1.Paste();
}

private void menuEditDelete_Click(object sender,
System.EventArgs e)
{
richTextBox1.Cut();
}

private void menuEditSelectAll_Click(object sender,
System.EventArgs e)
{
richTextBox1.SelectAll();
}


private void menuFormatFont_Click(object sender,
System.EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.SelectionFont = fontDialog1.Font;
}
}

private void menuFormatColor_Click(object sender,
System.EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.SelectionColor = colorDialog1.Color;
}
}

private void menuFormatFontCharacterStyleBold_Click(
object sender, System.EventArgs e)
{
SetBold();
}

private void menuFormatFontCharacterStyleItalic_Click(
object sender, System.EventArgs e)
{
SetItalic();
}

private void menuFormatFontCharacterStyleUnderline_Click(
object sender, System.EventArgs e)
{
SetUnderline();
}

private void menuFormatFontCharacterStyleStrikeout_Click(
object sender, System.EventArgs e)
{
SetStrikeout();
}

private void menuFormatFontParagraphAlignmentLeft_Click(
object sender, System.EventArgs e)
{
richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
}

private void menuFormatFontParagraphAlignmentRight_Click(
object sender, System.EventArgs e)
{
richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
}

private void menuFormatFontParagraphAlignmentCenter_Click(
object sender, System.EventArgs e)
{
richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
}


private void menuHelpAbout_Click(object sender,
System.EventArgs e)
{
HelpAboutForm dlgAbout = new HelpAboutForm();
dlgAbout.ShowDialog();
}


/// < summary>
/// Создание нового файла
/// < /summary>
private void MenuFileNew()
{
if(m_DocumentChanged)
{
SaveDocumentNeededForm dialog = new
SaveDocumentNeededForm();
DialogResult result = dialog.ShowDialog();

switch(result)
{
case DialogResult.Yes:
{
MenuFileSaveAs();
break;
}
case DialogResult.Cancel:
{
return;
}
}
}

richTextBox1.Clear();
statusBarPanel2.Text = " ";
m_DocumentChanged = false;
}


/// < summary>
/// Открытие существующего файла
/// < /summary>
private void MenuFileOpen()
{
if(m_DocumentChanged)
{
SaveDocumentNeededForm dialog = new
SaveDocumentNeededForm();
DialogResult result = dialog.ShowDialog();

switch(result)
{
case DialogResult.Yes:
{
MenuFileSaveAs();
break;
}
case DialogResult.Cancel:
{
return;
}
}
}

if(openFileDialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK & &
openFileDialog1.FileName.Length > 0)
{
try
{
richTextBox1.LoadFile(openFileDialog1.FileName,
RichTextBoxStreamType.RichText);
}
catch (System.ArgumentException ex)
{
richTextBox1.LoadFile(openFileDialog1.FileName,
RichTextBoxStreamType.PlainText);
}
this.Text = " Файл [" + openFileDialog1.FileName + " ]";
statusBarPanel2.Text = " ";
m_DocumentChanged = false;
}
}


/// < summary>
/// Сохранение документа в новом файле
/// < /summary>
private void MenuFileSaveAs()
{
if(saveFileDialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK & &
saveFileDialog1.FileName.Length > 0)
{
richTextBox1.SaveFile(saveFileDialog1.FileName);
m_DocumentChanged = false;
this.Text = " Файл [" + saveFileDialog1.FileName + " ]";
statusBarPanel2.Text = " ";
}
}


/// < summary>
/// Обработка события PrintPage
/// < /summary>
private void PrintPageEventHandler(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
int lineCount = 0; // счетчик строк
float linesPerPage = 0; // количество строк на одной
// странице
float yLinePosition = 0; // текущая позиция при печати по
// вертикальной оси
string currentLine = null; // текст текущей строки

// Шрифт для печати текста
Font printFont = this.richTextBox1.Font;

// Кисть для печати текста
SolidBrush printBrush = new SolidBrush(Color.Black);

// Размер отступа слева
float leftMargin = e.MarginBounds.Left;

// Размер отступа сверху
float topMargin = e.MarginBounds.Top +
3*printFont.GetHeight(e.Graphics);

// Вычисляем количество строк на одной странице с учетом
// отступа
linesPerPage = (e.MarginBounds.Height -
6*printFont.GetHeight(e.Graphics)) /
printFont.GetHeight(e.Graphics);

// Цикл печати всех строк страницы
while(lineCount < linesPerPage & &
((currentLine=m_myReader.ReadLine())! = null))
{
// Вычисляем позицию очередной распечатываемой строки
yLinePosition = topMargin + (lineCount *
printFont.GetHeight(e.Graphics));

// Печатаем очередную строку
e.Graphics.DrawString(currentLine, printFont, printBrush,
leftMargin, yLinePosition, new StringFormat());

// Переходим к следующей строке
lineCount++;
}

// Печать колонтитулов страницы

// Номер текущей страницы
string sPageNumber = " Page " + m_PrintPageNumber.ToString();

// Вычисляем размеры прямоугольной области, занимаемой верхним
// колонтитулом страницы
SizeF stringSize = new SizeF();
stringSize = e.Graphics.MeasureString(sPageNumber, printFont,
e.MarginBounds.Right - e.MarginBounds.Left);

// Печатаем номер страницы
e.Graphics.DrawString(sPageNumber, printFont, printBrush,
e.MarginBounds.Right - stringSize.Width, e.MarginBounds.Top,
new StringFormat());

// Печатаем имя файла документа
e.Graphics.DrawString(this.Text, printFont, printBrush,
e.MarginBounds.Left, e.MarginBounds.Top,
new StringFormat());

// Кисть для рисования горизонтальной линии, отделяющей
// верхний колонтитул
Pen colontitulPen = new Pen(Color.Black);
colontitulPen.Width = 2;

// Рисуем верхнюю линию
e.Graphics.DrawLine(colontitulPen,
leftMargin, e.MarginBounds.Top +
printFont.GetHeight(e.Graphics) + 3,
e.MarginBounds.Right, e.MarginBounds.Top +
printFont.GetHeight(e.Graphics) + 3);

// Рисуем линию, отделяющую нижний колонтитул документа
e.Graphics.DrawLine(colontitulPen,
leftMargin, e.MarginBounds.Bottom - 3,
e.MarginBounds.Right, e.MarginBounds.Bottom - 3);

// Печатаем текст нижнего колонтитула
e.Graphics.DrawString(" SimpleNotepad, (c) Александр Фролов, https://www.frolov.pp.ru", printFont, printBrush,
e.MarginBounds.Left, e.MarginBounds.Bottom,
new StringFormat());

// Если напечатаны не все строки документа, переходим к
// следующей странице
if(currentLine! = null)
{
e.HasMorePages = true;
m_PrintPageNumber++;
}

// Иначе завершаем печать страницы
else
e.HasMorePages = false;

// Освобождаем ненужные более ресурсы
printBrush.Dispose();
colontitulPen.Dispose();
}

/// < summary>
/// Печать документа
/// < /summary>
private void MenuFilePrint()
{
m_PrintPageNumber = 1;
string strText = this.richTextBox1.Text;
m_myReader = new StringReader(strText);
Margins margins = new Margins(100, 50, 50, 50);
printDocument1.DefaultPageSettings.Margins = margins;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}
m_myReader.Close();
}

/// < summary>
/// Предварительный просмотр перед печатью документа
/// < /summary>
private void MenuFilePrintPreview()
{
m_PrintPageNumber = 1;
string strText = this.richTextBox1.Text;
m_myReader = new StringReader(strText);
Margins margins = new Margins(100, 50, 50, 50);
printDocument1.DefaultPageSettings.Margins = margins;
printPreviewDialog1.ShowDialog();
m_myReader.Close();
}

/// < summary>
/// Настройка параметров страницы
/// < /summary>
private void MenuFilePageSetup()
{
pageSetupDialog1.ShowDialog();
}

private void richTextBox1_TextChanged(object sender,
System.EventArgs e)
{
m_DocumentChanged = true;
statusBarPanel2.Text = " Изменено";
}

/// < summary>
/// Установка стиля символов Bold
/// < /summary>
private void SetBold()
{
if (richTextBox1.SelectionFont! = null)
{
System.Drawing.Font currentFont =
richTextBox1.SelectionFont;
System.Drawing.FontStyle newFontStyle;

if (richTextBox1.SelectionFont.Bold == true)
{
newFontStyle = FontStyle.Regular;
}
else
{
newFontStyle = FontStyle.Bold;
}

richTextBox1.SelectionFont = new Font(
currentFont.FontFamily, currentFont.Size, newFontStyle);

CheckMenuFontCharacterStyle();
}
}

/// < summary>
/// Установка стиля символов Italic
/// < /summary>
private void SetItalic()
{
if (richTextBox1.SelectionFont! = null)
{
System.Drawing.Font currentFont =
richTextBox1.SelectionFont;
System.Drawing.FontStyle newFontStyle;
CheckMenuFontCharacterStyle();

if (richTextBox1.SelectionFont.Italic == true)
{
newFontStyle = FontStyle.Regular;
}
else
{
newFontStyle = FontStyle.Italic;
}

richTextBox1.SelectionFont = new Font(
currentFont.FontFamily, currentFont.Size, newFontStyle);

CheckMenuFontCharacterStyle();
}
}

/// < summary>
/// Установка стиля символов Underline
/// < /summary>
private void SetUnderline()
{
if (richTextBox1.SelectionFont! = null)
{
System.Drawing.Font currentFont =
richTextBox1.SelectionFont;
System.Drawing.FontStyle newFontStyle;
CheckMenuFontCharacterStyle();

if (richTextBox1.SelectionFont.Underline == true)
{
newFontStyle = FontStyle.Regular;
}
else
{
newFontStyle = FontStyle.Underline;
}

richTextBox1.SelectionFont = new Font(
currentFont.FontFamily, currentFont.Size, newFontStyle);

CheckMenuFontCharacterStyle();
}
}

/// < summary>
/// Установка стиля символов Strikeout
/// < /summary>
private void SetStrikeout()
{
if (richTextBox1.SelectionFont! = null)
{
System.Drawing.Font currentFont =
richTextBox1.SelectionFont;
System.Drawing.FontStyle newFontStyle;

if (richTextBox1.SelectionFont.Strikeout == true)
{
newFontStyle = FontStyle.Regular;
}
else
{
newFontStyle = FontStyle.Strikeout;
}

richTextBox1.SelectionFont = new Font(
currentFont.FontFamily, currentFont.Size, newFontStyle);

CheckMenuFontCharacterStyle();
}
}

/// < summary>
/// Установка отметки строк меню Font-> CharacterStyle
/// < /summary>
private void CheckMenuFontCharacterStyle()
{
if(richTextBox1.SelectionFont.Bold == true)
{
menuFormatFontCharacterStyleBold.Checked = true;
}
else
{
menuFormatFontCharacterStyleBold.Checked = false;
}

if(richTextBox1.SelectionFont.Italic == true)
{
menuFormatFontCharacterStyleItalic.Checked = true;
}
else
{
menuFormatFontCharacterStyleItalic.Checked = false;
}

if(richTextBox1.SelectionFont.Underline == true)
{
menuFormatFontCharacterStyleUnderline.Checked = true;
}
else
{
menuFormatFontCharacterStyleUnderline.Checked = false;
}

if(richTextBox1.SelectionFont.Strikeout == true)
{
menuFormatFontCharacterStyleStrikeout.Checked = true;
}
else
{
menuFormatFontCharacterStyleStrikeout.Checked = false;
}
}

private void toolBar1_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (toolBar1.Buttons.IndexOf(e.Button))
{
case 0:
{
MenuFileNew(); break;
}
case 1:
MenuFileOpen(); break;
case 2:
MenuFileSaveAs(); break;
case 4:
richTextBox1.Cut(); break;
case 5:
richTextBox1.Copy(); break;
case 6:
richTextBox1.Paste(); break;
case 8:
MenuFilePrintPreview(); break;
case 9:
MenuFilePrint(); break;
}

}

private void MenuSelect(object sender, System.EventArgs e)
{
MenuItem mi = (MenuItem) sender;
string ms;
switch(mi.Text)
{
case " & New": ms = " Новый документ"; break;
case " & Open...": ms = " Открыть документ"; break;
case " & Save": ms = " Сохранить документ"; break;
case " & Save As...": ms = " Сохранить документ"; break;
case " Page Set& up...": ms = " Параметры страницы"; break;
case " Print Pre& view...": ms = " Предварительный просмотр";
break;
case " & Print...": ms = " Печатать документ"; break;
case " Exit": ms = " Завершение работы"; break;
case " & Undo": ms = " Отменить ввод"; break;
case " & Redo": ms = " Повторить ввод"; break;
case " Cu& t": ms = " Вырезать"; break;
case " & Copy": ms = " Скопировать"; break;
case " & Paste": ms = " Вставить"; break;
case " & Delete": ms = " Удалить"; break;
case " & Select All": ms = " Выделить все"; break;
case " & Font...": ms = " Выбрать шрифт"; break;
case " C& olor...": ms = " Выбрать цвет"; break;
case " & Bold": ms = " Жирный шрифт"; break;
case " & Italic": ms = " Наклонный шрифт"; break;
case " & Underline": ms = " Подчеркивание"; break;
case " & Strikeout": ms = " Перечеркивание"; break;
case " & Left": ms = " Выравнивание по левой границе"; break;
case " & Right": ms = " Выравнивание по правой границе";
break;
case " & Center": ms = " Центровка"; break;
case " & About...": ms = " О программе"; break;
default: ms = " "; break;
}

statusBarPanel1.Text = ms;
}

private void menuHelpRegister_Click(object sender, System.EventArgs e)
{
RegisterForm dialog = new RegisterForm();
if(DialogResult.Yes == dialog.ShowDialog())
{
string body = " Данные регистрации: ";

body += " Name: " + dialog.UserName;
body += ", Email: " + dialog.UserEmail;
body += ", Level: " + dialog.UserLevel;
body += ", Gender: " + dialog.UserGender;
body += ", FavoriteOS: " + dialog.FavoriteOS;
body += ", SendNews: " + dialog.SendNews;
body += ", SendLetter: " + dialog.SendLetter;
body += ", BirthDay: " + dialog.UserBirthDay;
body += ", Comment: " + dialog.UserComment;

System.Diagnostics.Process.Start(
" mailto: alexandre@frolov.pp.ru? subject=Регистрация& body="
+ body);
}
}
}
}






© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.