Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. Windows. Forms;
Using System. Drawing. Drawing2D;
Using System. IO;
Using System. Drawing. Imaging;
The namespace pencil
{
Public partial class FormMain: Form
{
//define a list of generic collection objects, save all the figure yuan
Private List
//define the list collection objects, temporarily hold bai withdrawn figure yuan
Private List
//save the map of temporary yuan
Private Shape _tempShape=null;
//save the current drawing type
Private DrawType _drawType=DrawType. Line;
//save the current drawing the line width (the default is 10)
Private int _drawWidth=10;
//save the current drawing color (the default is red)
Private Color _drawColor=Color. Red;
//save BufferedGraphicsContext object, the object is used to separate image buffer allocation and management
BufferedGraphicsContext _bufGraphCont=null;
//save BufferedGraphics object (image buffer)
BufferedGraphics _bufGraph=null;
//save the current graphic file name (the default is empty)
Private string _fileName="";
//whether need to keep the tag
Private Boolean _saveFlag=false;
//save image scaling
Private double _zoomRatio=1;
//save paneldraw initial window size
Private Size _panelDrawlnitSize=new Size (0, 0);
//constructor
Public FormMain ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
}
Private void FormMain_MouseDown (object sender, MouseEventArgs e)
{
}
Private void FormMain_MouseUp (object sender, MouseEventArgs e)
{
}
Private void FormMain_Paint (object sender, PaintEventArgs e)
{
}
Private void MenultemLine_Click (object sender, EventArgs e)
{
_drawType=DrawType. Line;
}
Private void MenultemRectangle_Click (object sender, EventArgs e)
{
_drawType=DrawType. A Rectangle;
}
Private void MenultemCircle_Click (object sender, EventArgs e)
{
_drawType=DrawType. Circle;
}
Private void MenultemStop_Click (object sender, EventArgs e)
{
_drawType=DrawType. Stop;
}
Private void FormMain_Load (object sender, EventArgs e)
{
//get the current application of BufferedGraphicsContext object, by using double buffer technique to reduce or eliminate redraw flashing drawing when
_bufGraphCont=BufferedGraphicsManager. Current;
//use the panel. CreateGraphics () the size of the pixel format to create the same to the specified graphics buffer
_bufGraph=_bufGraphCont. The Allocate (panelDraw. CreateGraphics (), panelDraw. ClientRectangle);
//to empty the graphics buffer
_bufGraph. Graphics. Clear (Color. White);
//set the anti-aliasing smoothing model
_bufGraph. Graphics. SmoothingMode=SmoothingMode. AntiAlias;
//save paneldraw initial window size
_panelDrawlnitSize. Width=panelDraw. Width;
_panelDrawlnitSize. Height=panelDraw. Height;
//disable the undo menu and undo button
MenuItemUndo. Enabled=false;
ToolStripButtonUndo. Enabled=false;
//disable redo menu and redo button
MenuItemRedo. Enabled=false;
ToolStripButtonRedo. Enabled=false;
//Cursor penCur=new Cursor (" pen. Cur ");
//this. Cursor=penCur;
//the menu, toolbar, status bar is set to the default arrow cursor
MenuStrip1. The Cursor=your Cursors. The Arrow;
ToolStrip1. The Cursor=your Cursors. The Arrow;
StatusStrip1. The Cursor=your Cursors. The Arrow;
}
Private void FormMain_MouseMove (object sender, MouseEventArgs e)
{
}
Private void MenuItemWidth_Click (object sender, EventArgs e)
{
//create a new line width dialog object
DlgPenWidth DlgPenWidth=new DlgPenWidth ();
//set the line width of the default display dialog line width values
DlgPenWidth. NumericUpDownWidth. Value=https://bbs.csdn.net/topics/_drawWidth;
//show the line width, and dialog box, determine whether to click the ok button
If (dlgPenWidth ShowDialog (this)==DialogResult. OK)
{
//save the users to set the line width
_drawWidth=(int) (dlgPenWidth. NumericUpDownWidth. Value);
}
}
Private void MenuItemColor_Click (object sender, EventArgs e)
{
//set the color selected by default color dialog
ColorDialog1. Color=_drawColor;
//display color dialog box, determine whether to click the OK button
If (colorDialog1 ShowDialog (this)==DialogResult. OK)
{
//save the color of the user Settings to _drawColor
_drawColor=colorDialog1. Color;
}
}
Private void MenultemUndo_Click (object sender, EventArgs e)
{
If (_listShape Count!=0)
{
//delete the previously saved to a temporary
_listTempShape. Add (_listShape [_listShape. Count - 1]).
//delete list last figure yuan
_listShape. RemoveAt (_listShape. Count - 1);
//to empty the graphics buffer
_bufGraph. Graphics. Clear (Color. White);
//map all yuan each to the graphics buffer
Foreach (Shape Shape in _listShape)
shape. The Draw (_bufGraph. Graphics, DashStyle. Solid)
_bufGraph. Render (panelDraw. CreateGraphics ());
//determine whether to ban the undo menu
If (_listShape. Count==0)
MenuItemUndo. Enabled=false;
ToolStripButtonUndo. Enabled=false;
//enabled redo menu
MenuItemRedo. Enabled=true;
ToolStripButtonRedo. Enabled=true;
//set to save tag to true
_saveFlag=true;
}
}nullnullnullnullnullnullnullnull