Encoding is a type of entertainment. I not only make a living, but also look at it as a toy. The design of complex, multi-functional software is indeed very valuable, but small programs are more entertaining.
You can see a small program zoomit, which can zoom in the screen and mark it on the screen. These interesting functions are useful for demonstration! Next I will use C #. Net to design a similar program "demo assistant ". Today, we will first implement the graffiti function on the screen.
(If you have any questions or suggestions, contact me: Email: chuangen@126.com, website: http://chuangen.name /)
Permanent link to this article: http://chuangen.name/archives/2008/08/02/demo-helper-part1.html
Ideas
The Screen Drawing principle is to start a full screen form, use the current screen as the background image, and draw on the form.
Select the screen to draw:
- Screen screen = screen. primaryscreen;
Full Screen form
To start the full screen window, set the following properties:
This. formborderstyle = formborderstyle. none; // no border <br/> This. showintaskbar = false; <br/> This. topmost = true; // keep at the beginning <br/> This. bounds = screen. bounds; // set to overfill the screen
Screen Copy
The graphics. copyfromscreen method is provided in. net2.0 to simplify the Screen Copy code. The following code writes the home screen to a bitmap instance.
Rectangle bounds = screen. bounds; <br/> backimage = new Bitmap (bounds. width, bounds. height); <br/> graphics G = graphics. fromimage (backimage); <br/> G. copyfromscreen (bounds. location, new point (0, 0), bounds. size); <br/> G. dispose ();
Record the mouse track
The onmousedown, onmouseup, and onmousemove methods of the reloaded form are drawn to obtain the path of the mouse drag and store a curve in an array of point. When the mouse moves, if the mouse has been pressed, add the mouse coordinates to the curve.
Because the drawn curves may have different color, line width, and other attributes, we can define a class to store curve data, as shown below:
/// <Summary> <br/> // data class of a curve. <Br/> // </Summary> <br/> public class curvedata <br/> {<br/> color = color. black; <br/> float width = 1.0f; <br/> point [] points; <br/> // <summary> <br/> // curve color <br/> /// </Summary> <br/> Public color <br />{< br/> get {return color ;} <br/>}< br/> /// <summary> <br/> // curve width <br/> /// </Summary> <br/> public float width <br/>{< br/> get {return width ;} <br/>}< br/> // <s Ummary> <br/> // paint brush used to draw the curve. <Br/> // </Summary> <br/> Public pen <br/> {<br/> get {return new pen (color, width );} <br/>}< br/> /// <summary> <br/> // store the coordinates of each point in the curve. <Br/> // </Summary> <br/> Public point [] points <br/>{< br/> get {return points ;} <br/>}</P> <p> // <summary> <br/> // constructor. <Br/> // </Summary> <br/> // <Param name = "color"/> curve color </param> <br/> // /<Param name = "width"/> line width </param> <br/> // <Param name = "points"/> coordinate point data </param> <br/> Public curvedata (color, float width, point [] points) <br/>{< br/> This. color = color; <br/> This. width = width; <br/> This. points = points; <br/>}< br/>
Draw data
Reload the onpaint method, first draw the screen, and then draw each curve to achieve the graffiti function. Shows the effect (the curve in the figure shows the annotation effect ):
Notes
1. Whenever a point is added to a curve, you only need to draw a line segment from the last point of the original curve to the point. All curves must be drawn only when the screen is refreshed.
2. Be sure to enable the double buffer setting (doublebuffered) of the form to reduce or avoid screen blinking.
(If you have any questions or suggestions, contact me: Email: chuangen@126.com, website: http://chuangen.name /)
The screen annotation function is complete. Next time, we will implement other functions of the "demo assistant.