📄 drawingapp.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
namespace MDICSharp
{
public class frmChild : System.Windows.Forms.Form
{
#region frmChild definitions
private System.Windows.Forms.MenuItem menuZoom;
private System.Windows.Forms.MenuItem miZoomIn;
private System.Windows.Forms.MenuItem miZoomOut;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem miZoomRest;
private System.Windows.Forms.MenuItem menuHelp;
private System.Windows.Forms.MainMenu menuMain;
#endregion
private System.ComponentModel.IContainer components;
private Document m_doc;
private int nMouseDown = 0;
string currentFilename ;
// my member variables
// enumeration for shape types
enum ShapeType {cursor, rectangle, ellipse, triangle, line};
// determines current shape type
private ShapeType currShape;
// current shape
private Shape shape;
// holds mouse position
private Point mousePt;
private Point mousePt1;
private Point mousePt2;
// array of shapes
private ArrayList shapesArr;
// if some drawing should take place
bool bDrawAllowed;
// if a shape is moved
bool bMovingShape;
private Brush m_brush = new SolidBrush(Color.YellowGreen);
private Pen m_pen = new Pen(Color.Tomato);
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem miPenColor;
private System.Windows.Forms.MenuItem miBrushColor;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem mnuAbout;
private System.Windows.Forms.MenuItem mnuHelpTopics;
private System.Windows.Forms.MenuItem menuShape;
private System.Windows.Forms.MenuItem miRect;
private System.Windows.Forms.MenuItem miEllipse;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem miTriangle;
private System.Windows.Forms.MenuItem miLine;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarRect;
private System.Windows.Forms.ToolBarButton toolBarEllipse;
private System.Windows.Forms.ToolBarButton toolBarTriangle;
private System.Windows.Forms.ToolBarButton toolBarLine;
private System.Windows.Forms.ImageList imageList1;
// file name for load and save methods
string filename;
public frmChild()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// member variables initialization
currShape = ShapeType.cursor;
shape = null;
// mousePt = null;
// filename = "";
shapesArr = new ArrayList();
bDrawAllowed = false;
bMovingShape = false;
}
/// <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(frmChild));
this.menuMain = new System.Windows.Forms.MainMenu();
this.menuShape = new System.Windows.Forms.MenuItem();
this.miRect = new System.Windows.Forms.MenuItem();
this.miEllipse = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.miTriangle = new System.Windows.Forms.MenuItem();
this.miLine = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.miPenColor = new System.Windows.Forms.MenuItem();
this.miBrushColor = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
this.menuZoom = new System.Windows.Forms.MenuItem();
this.miZoomIn = new System.Windows.Forms.MenuItem();
this.miZoomOut = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.miZoomRest = new System.Windows.Forms.MenuItem();
this.menuHelp = new System.Windows.Forms.MenuItem();
this.mnuHelpTopics = new System.Windows.Forms.MenuItem();
this.mnuAbout = new System.Windows.Forms.MenuItem();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarRect = new System.Windows.Forms.ToolBarButton();
this.toolBarEllipse = new System.Windows.Forms.ToolBarButton();
this.toolBarTriangle = new System.Windows.Forms.ToolBarButton();
this.toolBarLine = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// menuMain
//
this.menuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuShape,
this.menuItem4,
this.menuZoom,
this.menuHelp});
//
// menuShape
//
this.menuShape.Index = 0;
this.menuShape.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miRect,
this.miEllipse,
this.menuItem3,
this.miTriangle,
this.miLine});
this.menuShape.Text = "&Shape";
//
// miRect
//
this.miRect.Index = 0;
this.miRect.Text = "&Rectangle";
this.miRect.Click += new System.EventHandler(this.miRect_Click);
//
// miEllipse
//
this.miEllipse.Index = 1;
this.miEllipse.Text = "&Ellipse";
this.miEllipse.Click += new System.EventHandler(this.miEllipse_Click);
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.Text = "-";
//
// miTriangle
//
this.miTriangle.Index = 3;
this.miTriangle.Text = "Triangle";
this.miTriangle.Click += new System.EventHandler(this.miTriangle_Click);
//
// miLine
//
this.miLine.Index = 4;
this.miLine.Text = "Line";
this.miLine.Click += new System.EventHandler(this.miLine_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miPenColor,
this.miBrushColor,
this.menuItem6});
this.menuItem4.Text = "Settings";
//
// miPenColor
//
this.miPenColor.Index = 0;
this.miPenColor.Text = "PenColor";
this.miPenColor.Click += new System.EventHandler(this.miPenColor_Click);
//
// miBrushColor
//
this.miBrushColor.Index = 1;
this.miBrushColor.Text = "BrushColor";
this.miBrushColor.Click += new System.EventHandler(this.miBrushColor_Click);
//
// menuItem6
//
this.menuItem6.Index = 2;
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem7,
this.menuItem8,
this.menuItem9,
this.menuItem11,
this.menuItem12,
this.menuItem5,
this.menuItem10,
this.menuItem13,
this.menuItem14,
this.menuItem15});
this.menuItem6.Text = "Pen Width";
//
// menuItem7
//
this.menuItem7.Index = 0;
this.menuItem7.Text = "1";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem8
//
this.menuItem8.Index = 1;
this.menuItem8.Text = "2";
this.menuItem8.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem9
//
this.menuItem9.Index = 2;
this.menuItem9.Text = "3";
this.menuItem9.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem11
//
this.menuItem11.Index = 3;
this.menuItem11.Text = "4";
this.menuItem11.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem12
//
this.menuItem12.Index = 4;
this.menuItem12.Text = "5";
this.menuItem12.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem5
//
this.menuItem5.Index = 5;
this.menuItem5.Text = "6";
this.menuItem5.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem10
//
this.menuItem10.Index = 6;
this.menuItem10.Text = "7";
this.menuItem10.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem13
//
this.menuItem13.Index = 7;
this.menuItem13.Text = "8";
this.menuItem13.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem14
//
this.menuItem14.Index = 8;
this.menuItem14.Text = "9";
this.menuItem14.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem15
//
this.menuItem15.Index = 9;
this.menuItem15.Text = "10";
this.menuItem15.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuZoom
//
this.menuZoom.Index = 2;
this.menuZoom.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miZoomIn,
this.miZoomOut,
this.menuItem2,
this.miZoomRest});
this.menuZoom.Text = "&Zoom";
//
// miZoomIn
//
this.miZoomIn.Index = 0;
this.miZoomIn.Text = "Zoom &In";
this.miZoomIn.Click += new System.EventHandler(this.miZoomIn_Click);
//
// miZoomOut
//
this.miZoomOut.Index = 1;
this.miZoomOut.Text = "Zoom &Out";
//
// menuItem2
//
this.menuItem2.Index = 2;
this.menuItem2.Text = "-";
//
// miZoomRest
//
this.miZoomRest.Index = 3;
this.miZoomRest.Text = "Zoom &Restore";
//
// menuHelp
//
this.menuHelp.Index = 3;
this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuHelpTopics,
this.mnuAbout});
this.menuHelp.Text = "&Help";
//
// mnuHelpTopics
//
this.mnuHelpTopics.Index = 0;
this.mnuHelpTopics.Text = "HelpTopics";
this.mnuHelpTopics.Click += new System.EventHandler(this.mnuHelpTopics_Click);
//
// mnuAbout
//
this.mnuAbout.Index = 1;
this.mnuAbout.Text = "About";
this.mnuAbout.Click += new System.EventHandler(this.mnuAbout_Click);
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarRect,
this.toolBarEllipse,
this.toolBarTriangle,
this.toolBarLine});
this.toolBar1.ButtonSize = new System.Drawing.Size(56, 36);
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(524, 42);
this.toolBar1.TabIndex = 2;
this.toolBar1.TabStop = true;
this.toolBar1.Tag = "";
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick_1);
//
// toolBarRect
//
this.toolBarRect.ImageIndex = 0;
this.toolBarRect.Text = "Rectangle";
//
// toolBarEllipse
//
this.toolBarEllipse.ImageIndex = 1;
this.toolBarEllipse.Text = "Ellipse";
//
// toolBarTriangle
//
this.toolBarTriangle.ImageIndex = 2;
this.toolBarTriangle.Text = "Triangle";
//
// toolBarLine
//
this.toolBarLine.ImageIndex = 3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -