.
 


       .
JAVA
.

[] [] []

C#


.. , ..

1. SimpleNotepad

SimpleNotepad, 4 5 .

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)
, http://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);
}
}
}
}

1-2. ch05\SimpleNotepad\SaveDocumentNeededForm.cs

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

namespace SimpleNotepad
{
/// <summary>
/// Summary description for SaveDocumentNeededForm.
/// </summary>
public class SaveDocumentNeededForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button buttonYes;
private System.Windows.Forms.Button buttonNo;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

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

/// <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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SaveDocumentNeededForm));
this.buttonYes = new System.Windows.Forms.Button();
this.buttonNo = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonYes
//
this.buttonYes.BackColor = System.Drawing.SystemColors.ControlLight;
this.buttonYes.DialogResult = System.Windows.Forms.DialogResult.Yes;
this.buttonYes.Location = new System.Drawing.Point(232, 88);
this.buttonYes.Name = "buttonYes";
this.buttonYes.TabIndex = 0;
this.buttonYes.Text = "
";
//
// buttonNo
//
this.buttonNo.BackColor = System.Drawing.SystemColors.ControlLight;
this.buttonNo.DialogResult = System.Windows.Forms.DialogResult.No;
this.buttonNo.Location = new System.Drawing.Point(232, 120);
this.buttonNo.Name = "buttonNo";
this.buttonNo.TabIndex = 1;
this.buttonNo.Text = "
";
//
// buttonCancel
//
this.buttonCancel.BackColor = System.Drawing.SystemColors.ControlLight;
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location =
new System.Drawing.Point(232, 152);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "
";
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(200, 136);
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.label1.Location = new System.Drawing.Point(208, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(104, 23);
this.label1.TabIndex = 4;
this.label1.Text = "
!";
//
// label2
//
this.label2.Location = new System.Drawing.Point(208, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(152, 16);
this.label2.TabIndex = 5;
this.label2.Text = "
.";
//
// label3
//
this.label3.Location = new System.Drawing.Point(208, 56);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(136, 23);
this.label3.TabIndex = 6;
this.label3.Text = "
?";
//
// SaveDocumentNeededForm
//
this.AcceptButton = this.buttonYes;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(352, 189);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label3,
this.label2,
this.label1,
this.pictureBox1,
this.buttonCancel,
this.buttonNo,
this.buttonYes});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "SaveDocumentNeededForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "
";
this.ResumeLayout(false);

}
#endregion
}
}

1-3. ch05\SimpleNotepad\RegisterForm.cs

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

namespace SimpleNotepad
{
/// <summary>
/// Summary description for RegisterForm.
/// </summary>
public class RegisterForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBoxName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxEmail;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox comboBoxLevel;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.RadioButton radioButton5;
private System.Windows.Forms.TextBox textBoxFavoriteOS;
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.CheckBox checkBoxSendNews;
private System.Windows.Forms.CheckBox checkBoxSendLetter;
private System.Windows.Forms.TextBox textBoxComment;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.GroupBox groupBoxGender;
private System.Windows.Forms.GroupBox groupBoxOS;
private System.Windows.Forms.ErrorProvider errorProvider1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

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

/// <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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBoxName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBoxEmail = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.comboBoxLevel = new System.Windows.Forms.ComboBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.groupBoxGender = new System.Windows.Forms.GroupBox();
this.groupBoxOS = new System.Windows.Forms.GroupBox();
this.textBoxFavoriteOS = new System.Windows.Forms.TextBox();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.monthCalendar1 = new
System.Windows.Forms.MonthCalendar();
this.label4 = new System.Windows.Forms.Label();
this.checkBoxSendNews = new System.Windows.Forms.CheckBox();
this.checkBoxSendLetter = new System.Windows.Forms.CheckBox();
this.textBoxComment = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.errorProvider1 = new
System.Windows.Forms.ErrorProvider();
this.groupBoxGender.SuspendLayout();
this.groupBoxOS.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.Control;
this.button1.DialogResult =
System.Windows.Forms.DialogResult.Yes;
this.button1.Location = new System.Drawing.Point(117, 480);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 23);
this.button1.TabIndex = 0;
this.button1.Text = "
";
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.Control;
this.button2.DialogResult =
System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(253, 480);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(112, 23);
this.button2.TabIndex = 1;
this.button2.Text = "
";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(108, 56);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(121, 20);
this.textBoxName.TabIndex = 2;
this.textBoxName.Text = "";
this.textBoxName.Validating +=
new System.ComponentModel.CancelEventHandler(
this.textBoxName_Validating);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.label1.Location = new System.Drawing.Point(29, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(424, 32);
this.label1.TabIndex = 3;
this.label1.Text = "
";
//
// label2
//
this.label2.Location = new System.Drawing.Point(48, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 23);
this.label2.TabIndex = 4;
this.label2.Text = "
. . .";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 5;
this.label3.Text = "
E-Mail:";
this.label3.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// textBoxEmail
//
this.textBoxEmail.Location =
new System.Drawing.Point(108, 88);
this.textBoxEmail.Name = "textBoxEmail";
this.textBoxEmail.Size = new System.Drawing.Size(121, 20);
this.textBoxEmail.TabIndex = 6;
this.textBoxEmail.Text = "";
this.textBoxEmail.Validating +=
new System.ComponentModel.CancelEventHandler(
this.textBoxEmail_Validating);
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 120);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(88, 16);
this.label5.TabIndex = 9;
this.label5.Text = "
:";
this.label5.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// comboBoxLevel
//
this.comboBoxLevel.Items.AddRange(new object[] {
"
",
"
",
"
",
"
",
"
"});
this.comboBoxLevel.Location =
new System.Drawing.Point(108, 120);
this.comboBoxLevel.Name = "comboBoxLevel";
this.comboBoxLevel.Size = new System.Drawing.Size(121, 21);
this.comboBoxLevel.TabIndex = 10;
this.comboBoxLevel.Text = "
";
//
// radioButton1
//
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(16, 16);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(48, 24);
this.radioButton1.TabIndex = 12;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "
.";
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(64, 16);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(48, 24);
this.radioButton2.TabIndex = 13;
this.radioButton2.Text = "
.";
//
// groupBoxGender
//
this.groupBoxGender.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioButton2,
this.radioButton1});
this.groupBoxGender.Location =
new System.Drawing.Point(253, 56);
this.groupBoxGender.Name = "groupBoxGender";
this.groupBoxGender.Size = new System.Drawing.Size(176, 48);
this.groupBoxGender.TabIndex = 14;
this.groupBoxGender.TabStop = false;
this.groupBoxGender.Text = "
";
//
// groupBoxOS
//
this.groupBoxOS.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxFavoriteOS,
this.radioButton5,
this.radioButton4,
this.radioButton3});
this.groupBoxOS.Location = new System.Drawing.Point(253, 112);
this.groupBoxOS.Name = "groupBoxOS";
this.groupBoxOS.Size = new System.Drawing.Size(176, 144);
this.groupBoxOS.TabIndex = 15;
this.groupBoxOS.TabStop = false;
this.groupBoxOS.Text = "
";
//
// textBoxFavoriteOS
//
this.textBoxFavoriteOS.Enabled = false;
this.textBoxFavoriteOS.Location =
new System.Drawing.Point(40, 104);
this.textBoxFavoriteOS.Name = "textBoxFavoriteOS";
this.textBoxFavoriteOS.TabIndex = 3;
this.textBoxFavoriteOS.Text = "";
//
// radioButton5
//
this.radioButton5.Location = new System.Drawing.Point(16, 72);
this.radioButton5.Name = "radioButton5";
this.radioButton5.Size = new System.Drawing.Size(152, 24);
this.radioButton5.TabIndex = 2;
this.radioButton5.Text = "
(, )";
this.radioButton5.CheckedChanged +=
new System.EventHandler(this.radioButton5_CheckedChanged);
//
// radioButton4
//
this.radioButton4.Location = new System.Drawing.Point(16, 48);
this.radioButton4.Name = "radioButton4";
this.radioButton4.Size = new System.Drawing.Size(64, 24);
this.radioButton4.TabIndex = 1;
this.radioButton4.Text = "Linux";
//
// radioButton3
//
this.radioButton3.Checked = true;
this.radioButton3.Location = new System.Drawing.Point(16, 24);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(88, 24);
this.radioButton3.TabIndex = 0;
this.radioButton3.TabStop = true;
this.radioButton3.Text = "MS Windows";
//
// monthCalendar1
//
this.monthCalendar1.Location =
new System.Drawing.Point(37, 184);
this.monthCalendar1.MaxSelectionCount = 1;
this.monthCalendar1.Name = "monthCalendar1";
this.monthCalendar1.TabIndex = 16;
//
// label4
//
this.label4.Location = new System.Drawing.Point(37, 160);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(152, 16);
this.label4.TabIndex = 17;
this.label4.Text = "
:";
//
// checkBoxSendNews
//
this.checkBoxSendNews.Checked = true;
this.checkBoxSendNews.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxSendNews.Location =
new System.Drawing.Point(253, 288);
this.checkBoxSendNews.Name = "checkBoxSendNews";
this.checkBoxSendNews.Size = new System.Drawing.Size(152, 16);
this.checkBoxSendNews.TabIndex = 18;
this.checkBoxSendNews.Text = "
";
//
// checkBoxSendLetter
//
this.checkBoxSendLetter.Checked = true;
this.checkBoxSendLetter.CheckState =
System.Windows.Forms.CheckState.Checked;
this.checkBoxSendLetter.Location = new
System.Drawing.Point(253, 304);
this.checkBoxSendLetter.Name = "checkBoxSendLetter";
this.checkBoxSendLetter.Size =
new System.Drawing.Size(168, 32);
this.checkBoxSendLetter.TabIndex = 19;
this.checkBoxSendLetter.Text = "
";
//
// textBoxComment
//
this.textBoxComment.Location =
new System.Drawing.Point(77, 384);
this.textBoxComment.Multiline = true;
this.textBoxComment.Name = "textBoxComment";
this.textBoxComment.Size = new System.Drawing.Size(328, 72);
this.textBoxComment.TabIndex = 20;
this.textBoxComment.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(77, 360);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(208, 23);
this.label6.TabIndex = 21;
this.label6.Text = "
:";
//
// errorProvider1
//
this.errorProvider1.DataMember = null;
//
// RegisterForm
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(482, 519);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label6,
this.textBoxComment,
this.checkBoxSendLetter,
this.checkBoxSendNews,
this.label4,
this.monthCalendar1,
this.groupBoxOS,
this.comboBoxLevel,
this.label5,
this.textBoxEmail,
this.label3,
this.label2,
this.label1,
this.textBoxName,
this.button2,
this.button1,
this.groupBoxGender});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "RegisterForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "
";
this.groupBoxGender.ResumeLayout(false);
this.groupBoxOS.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

private void radioButton5_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if(rb.Checked)
textBoxFavoriteOS.Enabled = true;
else
textBoxFavoriteOS.Enabled = false;
}

private void textBoxName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if(textBoxName.Text.Length == 0)
{
errorProvider1.SetError(textBoxName, "
");
}
else
errorProvider1.SetError(textBoxName, "");
}

private void textBoxEmail_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
string email = textBoxEmail.Text;

if(email.IndexOf('@') == -1 || email.IndexOf('.') == -1)
{
errorProvider1.SetError(textBoxEmail,
"
E-Mail");
}
else
errorProvider1.SetError(textBoxEmail, "");
}

public string UserName
{
get
{
return textBoxName.Text;
}
}

public string UserEmail
{
get
{
return textBoxEmail.Text;
}
}

public string UserLevel
{
get
{
return comboBoxLevel.Text;
}
}

public string UserComment
{
get
{
return textBoxComment.Text;
}
}

public string UserGender
{
get
{
for(int i=0; i < groupBoxGender.Controls.Count; i++)
{
RadioButton rb = (RadioButton)groupBoxGender.Controls[i];
if(rb.Checked)
return rb.Text;
}
return "";
}
}

public string FavoriteOS
{
get
{
for(int i=0; i < groupBoxOS.Controls.Count; i++)
{
if(groupBoxOS.Controls[i] is RadioButton)
{
RadioButton rb = (RadioButton)groupBoxOS.Controls[i];

if(rb.Checked)
{
if(rb.Name != radioButton5.Name)
return rb.Text;
else
return textBoxFavoriteOS.Text;
}
}
}
return "";
}
}

public string SendNews
{
get
{
if(checkBoxSendNews.Checked)
return "Yes";
else
return "No";
}
}

public string SendLetter
{
get
{
if(checkBoxSendLetter.Checked)
return "Yes";
else
return "No";
}
}

public string UserBirthDay
{
get
{
DateTime dt = monthCalendar1.SelectionStart;
return dt.Day + "." + dt.Month + "." + dt.Year;
}
}

}
}

1-4. ch05\SimpleNotepad\HelpAboutForm.cs

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

namespace SimpleNotepad
{
/// <summary>
/// Summary description for HelpAboutForm.
/// </summary>
public class HelpAboutForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.LinkLabel linkLabel2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

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

/// <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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(HelpAboutForm));
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.linkLabel2 = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor =
System.Drawing.SystemColors.ControlLight;
this.button1.DialogResult =
System.Windows.Forms.DialogResult.Cancel;
this.button1.Location = new System.Drawing.Point(92, 128);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "OK";
this.button1.Click +=
new System.EventHandler(this.button1_Click);
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(40, 64);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.label1.Location = new System.Drawing.Point(72, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(160, 24);
this.label1.TabIndex = 2;
this.label1.Text = "SimpleNotepad";
//
// label2
//
this.label2.Location = new System.Drawing.Point(72, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(100, 16);
this.label2.TabIndex = 3;
this.label2.Text = "Version 1.0";
//
// label3
//
this.label3.Location = new System.Drawing.Point(72, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(144, 16);
this.label3.TabIndex = 4;
this.label3.Text = "(c) Alexandre Frolov, 2003";
//
// linkLabel1
//
this.linkLabel1.Location = new System.Drawing.Point(72, 80);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(96, 16);
this.linkLabel1.TabIndex = 5;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "www.frolov.pp.ru";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// linkLabel2
//
this.linkLabel2.Location = new System.Drawing.Point(72, 96);
this.linkLabel2.Name = "linkLabel2";
this.linkLabel2.Size = new System.Drawing.Size(136, 16);
this.linkLabel2.TabIndex = 6;
this.linkLabel2.TabStop = true;
this.linkLabel2.Text = "alexandre@frolov.pp.ru";
this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked);
//
// HelpAboutForm
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Khaki;
this.CancelButton = this.button1;
this.ClientSize = new System.Drawing.Size(258, 167);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.linkLabel2,
this.linkLabel1,
this.label3,
this.label2,
this.label1,
this.pictureBox1,
this.button1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "HelpAboutForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "About SimpleNotepad";
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}

private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited =
true;
System.Diagnostics.Process.Start(linkLabel1.Text);
}

private void linkLabel2_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
linkLabel2.Links[linkLabel2.Links.IndexOf(e.Link)].Visited =
true;
System.Diagnostics.Process.Start(
"mailto:alexandre@frolov.pp.ru");
}
}
}

[] [] []


-: http://www.shop2you.ru/ , , 1991-2016