This article is a small example of developing software using C # for learning to share.
Ideas:
Capture screen pictures.
Gets the range to intercept, that is, the upper-left corner, the lower-right corner coordinate
Fill in the PictureBox.
Stroke function, highlighter, rectangle, eraser, copy, save function
Points of knowledge involved:
MenuStrip: Provides a menu system for the form. Menu sub-option with ToolStripMenuItem
ToolStrip: Provides a container for Windows toolbar objects. Use ToolStripButton "to indicate optional" containing text and images "as a toolbar child element
PictureBox: Represents the Windows picture box control that is used to display an image. However, this article overrides this space
Screen: Can be used to get work area
Graphics: Encapsulates a GDI + drawing surface. This class cannot be inherited. The CopyFromScreen method of this class is used to get the screen image
Mouse events: includes the Mousedown,mousemove,mouseup event to get the position of the mouse through the location in the MouseEventArgs.
Clipboard: Provides a way to put data on the system Clipboard and retrieve data from it. This class cannot be inherited.
Cursor: Sets the style of the cursor that the mouse displays.
OnPaint: Redraws the event, responding to this event when the control refreshes.
The following "main implementations, save, copy, draw rectangles, strokes, highlighter, eraser and other functions":
After saving the picture as follows:
--------------------------------------------------------------------------------------------------------------- ----------------
The core code is as follows:
To capture a screen image:
1 public Bitmap Getscreen () 2 {3 //Get the entire screen image, excluding taskbar 4 Rectangle Screenarea = Screen.getworkingarea (this); 5< C3/>bitmap bmp = New Bitmap (screenarea.width, screenarea.height); 6 using (Graphics g = graphics.fromimage (BMP)) 7 {8 g.copyfromscreen (0, 0, 0, 0, new Size (screenarea.width,s Creenarea.height)); 9 }10 return bmp;11 }
View Code
To draw graphics features:
1 #region Drawing function 2 3 protected override void OnPaint (PaintEventArgs pe) 4 {5 base. OnPaint (PE); 6 Graphics g = pe. Graphics; 7 Drawhistory (g); 8//Draw Current Line 9 if (Startdraw && this.curLine.PointList! = null && this.curLine.Point List.count > 0) {DrawLine (g,this.curline); Draw && This.curRect.Start! = NULL && this.curRect.End! = NULL && This.curRect.Start! = This.curre Ct. END) {DrawRectangle (g, this.currect); n} (+)-public void Drawhis Tory (Graphics g) {19//Draw line history (Linehistory! = null) Reach (Hline lh in Linehistory) (LH. Pointlist.count > (g, LH), 27 } 28} 29} 30//Draw Rectangle History if (recthistory! = null) 3 2 {hrectangle LH in recthistory) Lh. start!=null&& LH. End!=null && LH. Start!=lh. END) DrawRectangle (g, LH); 38} 39 } +//<summary> 44//Draw Line///</summary> 46 <param name= "G" ></param>//<param name= "line" ></param> private void DrawLine (Graphics g,hline line) {g.smoothingmode = Smoothingmode.antialias; n p = new Pen (line. LineColor, line. LineWidth)) 51 {52//Set start and end line cap p.startcap = Linecap.round; 54 P.endcap = Linecap.round; 55 56 Sets the join style for two consecutive paragraphs p.linejoin = Linejoin.round; G.drawcurve (p, line. Pointlist.toarray ()); Draw a smooth curve for me}//<summary> 63//Draw Rectangle///</summary >//<param name= "G" ></param>//<param name= "rect" ></param> 67 private void DrawRectangle (Graphics g, Hrectangle rect), G.smoothingmode = Smoothingmode.antia Lias The using (Pen p = new Pen (rect). LineColor, Rect. LineWidth)) 71 {72//Set start and end point line cap p.startcap = Linecap.round; 74 P.endcap = Linecap.round; 75 76//Set the join style for successive two segments p.linejoin = Linejoin.round; G.drawrectangle (P, rect. Start.x, Rect. Start.y, Rect. End.x-rect. Start.x, Rect. End.y-rect. START.Y); Draw Smooth curve---------------bayi--public void Earserp0) (int i = linehistory.count-1; I >= 0; i--) INE line = Linehistory[i]; The *. BOOL flag = FALSE; P1. pointlist) distance = Getdistance (P0, p1); Ath. Abs (distance) < 6) 92 {93//need to remove 94 flag = TRUE; 9 5 break; 98}, (flag) 100 {101 Linehistory.removeat (i); 102}103}104//Erase rectangle for (int i = Recthist Ory. Count-1; I >= 0; i--) 106 {107 Hrectangle rect = recthistory[i];108 109 if (p0. X>rect. Start.x && P0. X<rect. End.X && P0. Y > Rect. Start.y && P0. Y < rect. END.Y) {111 recthistory.removeat (i); 112}113}114 }115///<summary>117///To get distance between two points 118//</summary>119//<p Aram Name= "P0" ></param>120//<param name= "P1" ></param>121//<RETURNS></R eturns>122 private Double Getdistance (point p0, point p1) {123 return math.sqrt (Math.pow (p0. X-p1. X), 2) + Math.pow ((p0. Y-p1. Y), 2); 124}125 126 #endregion
view code