一个优秀的C#开源绘图软件 DrawTools

1、Extensions to DrawTools

Author

Mark Miller I develop software for a leading healthcare system in Northern Illinois.

  • Download updated demo – 55.57 KB
  • Download (VS 2010) updated source – 889.43 KB

一个优秀的C#开源绘图软件 DrawTools

From this dialog, you can Add new , change the names of the (s), and change the (s) visibility and which is . The “New Layer” column is checked whenever you click the “Add Layer” button. To delete Layer(s), simply check the “Deleted” column and close the dialog with the “Close” button. Remember only one Layer may be active at any one time. You will be reminded of this if you attempt to have more than one active. Also note the Active must be .

When the application runs, each object that is drawn is added to the maintained by the active . Note this relationship is preserved through saving and re-opening a drawing file.

Layers come in very handy when you want to draw “on top of” another image. For example, the image at the top of this article contains two layers. The following image shows the same picture with the Background Layer turned off:

一个优秀的C#开源绘图软件 DrawTools

Here is the same drawing with the Drawing Layer invisible and the Background Layer visible:

一个优秀的C#开源绘图软件 DrawTools

Objects on Layers which are visible but not active cannot be selected, moved, deleted, etc.

Each drawing object is added to the correct by the method in the class:

Implementing Zooming, Panning, and Rotation

Zooming, Panning, and Rotation are implemented by adding a few variables and some code to the and classes.

Zooming is controlled by buttons on the form, and also by the mouse wheel when Ctrl is held down.

Pan is controlled by the Hand button on the form, and can be cancelled by a right-click.

Rotation is controlled by buttons on the form – note Rotation affects the entire drawing.

Here is an example of all three in use:

Screenshot - DrawToolsRedux-3.png

The heart of this code is the method, which takes the “apparent” mouse position and converts it to a valid point based on the current Zoom level, Pan position, and Rotation:

This routine comes from Bob Powell’s excellent website. Through the use of the GDI+ Matrix class, the mouse point passed to this method is moved (Translate), Rotated, and Scaled based on the current PanX, PanY, Zoom, and Rotation values. The important thing to remember is that anytime you need to determine where the mouse pointer actually is in your drawing, you must call this method. You will see this method used throughout the program in the class as well as others. An example of its usage is shown here:

The current zoom level is controlled by the following simple routine:

Then in the method, the zoom, pan, and rotation values are used to alter the way the canvas is painted:

Update – 8/25/2007 – Individual Object Rotation & Bug Fixes

The primary advancement in this update is the ability to rotate individual objects – when one or more objects are selected, clicking the Rotate tools will rotate those objects instead of the entire drawing surface.

There is one caveat, however – the selection rectangle for the rotated object is not rotated – if someone can help with this, I would greatly appreciate it!

This update also includes several small bug fixes reported by users – thanks to all for reporting!

History

  • 3/6/2007
    • Original article uploaded to The Code Project
  • 3/6/2007
    • Updated to include more information on zoom/pan/rotation
  • 8/25/2007
    • Updated Individual Object Rotation
  • 9/27/2007
    • Added the missing links to the new source code
  • 12/23/2009
    • Added Tooltip control which appears when mouse is over an object. Tooltip displays the Center coordinates of the object for , and objects. For other objects, Tooltip displays starting and ending coordinates. objects do not display Tooltip.
      This was implemented adding the Tooltip control to the class. Each Object fills the property and the event in controls when the Tooltip is displayed and removed from the canvas. This implementation is not perfect, as the Tooltip flashes when displayed so is meant as an example of one way information about the object can be displayed.
      Perhaps a better way to do this would be to display information about the object in a separate “Information Window” and then only when the object is selected.
    • See the new source code for details.
  • 6/23/2010
    • Updated project to include object ordering fix that corrects the way objects are stacked when a file is opened
    • Updated project to Visual Studio 2010
    • See the new source code for details
  • 10/4/2011
    • Corrected several issues with Layers and layering

2、DrawTools 2014

Author

Arnault Bonafos, 16 Jan 2014

  • Download source – 85 KB
  • Download binaries – 37.9 KB

Introduction  

Current alternative is based on the CodeProject DrawTools 2005, built under Visual Studio C# 2010.

The main goal of this tip is to post and save the DrawTools project back to the community after some enhancements. The tip is short, as the improvements are minor.

A few improvements have been made, as follows:

  1. Add scroll bars to the draw area
  2. Handling of in the different tools provided by the original project
  3. Export of the drawing with jpeg format  

Background

Knowledge of C# is required, but this project shows the basics of UI programming under ‘.NET’.

Architecture

Dynamic handling for showing scroll bars

A dirty boolean is handled in , the canvas document, where it should be. To this property is associated a interface.

Hide   Copy Code

Every time the document is modified, look with the different draw tools, its property is set to and any is fired.

Hide   Copy Code

The class implements the , and every time the document is ”, it calls , which in turn computes the bounding box of the canvas document ().

Hide   Copy Code

This way, it implements the Mode/View/Controller design pattern, the being the model, being the View and the draw being the controller.

In the future, property should be handled in only one place (it is also handled in the class).

Export the graph to JPEG format

The DrawTools 2014 architecture is good enough to be followed to implement a new menu strip option.

    1. Add a menu item to the menu bar

      Simply open the MainForm designer and add the option

    2. Link the to a method to trigger the

      Hide   Copy Code

    3. Implement the user interface logic in the

      I let you look at the

    4. Subscribe method implementation to event.

Hide   Copy Code

  1. Implement logic to actually transform image bitmap into JPEG file.

    All is in the source code, I don’t copy it here as it is essentially technical stuff.

Result

The result is best shown by the following graph, obtained with a customized version of the DrawTools.

一个优秀的C#开源绘图软件 DrawTools

Points of Interest

Architecture is already well thought in the original project, please read the original document for insight about it.

  • DrawTools 2005

There was a bug where the status bar was hiding the horizontal scroll bar, but after some thorough inspection of the code, it has been fixed.

  • Issue on Stackoverflow

History

  1. Added scroll bars to the draw area
  2. Added a status bar
  3. Fixed a bug on the context menu when the scroll bar position is not 0
  4. Export of the drawing with jpeg format
  5. Fixed an with JPEG format export

Special thank you to Alex, who originally posted the DrawTools project on CodeProject.

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

 

 

相关资源:SAI绘画软件v1.3.1.0汉化绿色免费版_SAI-其它代码类资源-CSDN文库

来源:weixin_33739646

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2016年11月22日
下一篇 2016年11月22日

相关推荐