Danh mục

DrawTools

Số trang: 7      Loại file: doc      Dung lượng: 112.50 KB      Lượt xem: 8      Lượt tải: 0    
Hoai.2512

Phí tải xuống: 2,000 VND Tải xuống file đầy đủ (7 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

DrawTools sample shows how to create a Windows Forms application for drawinggraphic objects in a Windows client area using mouse and drawing tools. Drawing toolsimplemented in this sample are: Rectangle, Ellipse, Line, and Pencil. There are wellknowntechniques for creating such type of applications, like: interaction with mouse,flicker-free drawing, implementing of drawing and selection tools, objects selection,managing of objects Z-order etc. MFC developers may learn all this stuff from MFCsample DRAWCLI. DrawTools C# program reproduces some of DRAWCLIfunctionality and uses some design decisions from this sample....
Nội dung trích xuất từ tài liệu:
DrawTools • Download source code (C# 2005) - 72 KbIntroductionDrawTools sample shows how to create a Windows Forms application for drawinggraphic objects in a Windows client area using mouse and drawing tools. Drawing toolsimplemented in this sample are: Rectangle, Ellipse, Line, and Pencil. There are well-known techniques for creating such type of applications, like: interaction with mouse,flicker-free drawing, implementing of drawing and selection tools, objects selection,managing of objects Z-order etc. MFC developers may learn all this stuff from MFCsample DRAWCLI. DrawTools C# program reproduces some of DRAWCLIfunctionality and uses some design decisions from this sample.DrawTools solution contains two projects: DrawTools Windows Forms application andDocToolkit Class Library. DrawTools implements specific application stuff, andDocToolkit contains some standard classes for file managing.Main features of the DrawTools solution are described below.DrawTools classes • DrawArea - user control which fills main application window client area. Contains instance of the GraphicsList class. Draws graphic objects, handles mouse input passing commands to GraphicsList. • GraphicsList - list of graphic objects. Contains ArrayList of graphic objects. Talks with each graphic object by generic way using DrawObject methods. • DrawObject - abstract base class for all graphic objects. • DrawRectangle - rectangle graphic object. • DrawEllipise - ellipse graphic object. • DrawLine - line graphic object. • DrawPolygon - polygon graphic object. • Tool - abstract base class for all drawing tools. • ToolPointer - pointer tool (neutral tool). Contains implementation for selection, moving, resizing of graphic objects. • ToolObject - abstract base class for all tools which create new graphic object. • ToolRectangle - rectangle tool. • ToolEllipse - ellipse tool. • ToolLine - line tool. • ToolPolygon - polygon tool.DocToolkit LibraryDocToolkit Library contains a set of classes which may be used for creation ofdocument-centric Windows Forms applications. Instances of classes exported from theDocToolkit Library are kept in the main form of the DrawTools project and is used forgeneral file-related operations. • DocManager class: Makes file-related operations: open, new, save, updating of the form title, registering of file type for Windows Shell. Built using the article Creating Document-Centric Applications in Windows Forms by Chris Sells. • DragDropManager class: Allows to open files dropped from Windows Explorer in Windows Forms applications. • MruManager class: Manages Most Recently Used Files list. • PersistWindowState class: Allows to keep last window state in the Registry and restore it when form is loaded. Source: Saving and Restoring the Location, Size and Windows State of a .NET Form By Joel Matthias.Handling of Windows controls state at application idle timeEvery Windows Forms application has a number of controls like menu items, buttons,toolbar buttons etc. Depending on current situation and user commands, these controlsmay have different states: enabled/disabled, checked/unchecked, visible/invisible etc.Every user action may change this state. Setting of controls state in every messagehandler may be error-prone. Instead of this, it is better to manage controls state in somefunction which is called after every user action. MFC has the greatON_UPDATE_COMMAND_UI feature which allows to update toolbar buttons state atapplication idle time. Such a feature may be implemented also in .NET programs.Consider the situation when user clicks the Rectangle toolbar button. This button shouldbe checked, and previously active tool should be unchecked. Rectangle button messagehandler doesnt change form controls state, it just keeps current selection in somevariable. Idle message handler selects active tool and unselects inactive tool. Collapseprivate void Form1_Load(object sender, System.EventArgs e){ // Submit to Idle event to set controls state at idle time Application.Idle += delegate(object o, EventArgs a) { SetStateOfControls(); };}public void SetStateOfControls(){ // Select active tool tbPointer.Pushed = (drawArea.ActiveTool ==DrawArea.DrawToolType.Pointer); tbRectangle.Pushed =(drawArea.ActiveTool==DrawArea.DrawToolType.Rectangle); tbEllipse.Pushed = (drawArea.ActiveTool ==DrawArea.DrawToolType.Ellipse); tbLine.Pushed = (drawArea.ActiveTool == DrawArea.DrawToolType.Line); tbPolygon.Pushed = (drawArea.ActiveTool ==DrawArea.DrawToolType.Polygon); menuDrawPointer.Checked = (drawArea.ActiveTool ==DrawArea.DrawToolType.Pointer); menuDrawRectangle. ...

Tài liệu được xem nhiều: