C # GDI + simple Drawing

Source: Internet
Author: User
Tags dashed line in degrees

First, use pen brush

The main properties of a pen are:

Color (colors), dashcap (dash End shape), DashStyle (dash style), Endcap (line tail shape), StartCap (head shape), Width (thickness), etc.

We can use a pen to draw dashed lines, lines with arrows, and so on.

Pen p =NewPen (Color.Blue,5); Graphics g= This. CreateGraphics ();//not here in load, can it be in paint? //draw a dashed lineP.dashstyle = System.Drawing.Drawing2D.DashStyle.Dot;//defines the style of the dashed line as a pointG.drawline (P,Ten,Ten, $,Ten); //Custom Dashed linesP.dashpattern =New float[] {2,1};//set an array of dashes and blank partsG.drawline (P,Ten, -, $, -); //draw arrows, only useful for non-closed curvesP.dashstyle = System.Drawing.Drawing2D.DashStyle.Solid;//Restore Solid linesP.endcap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;//defines the style of the end of the line as an arrowG.drawline (P,Ten, -, $, -);            G.dispose (); P.dispose ();

Post-run Effects:

Ii. use of the bush

The role of paint brush: can be used to fill the shape, multilateral, oval, fan ....

    • SolidBrush: The simplest form of painting, painted with a solid color
    • HatchBrush: Similar to SolidBrush, but you can use this class to select a pattern to use from a large number of preset patterns, rather than a solid color
    • TextureBrush: Drawing with textures (like)
    • LinearGradientBrush: Drawing with two colors blended along a gradient
    • PathGradientBrush: Drawing with complex blend color gradients based on a unique path defined by the programmer
Graphics g = This. CreateGraphics ();//not here in load, can it be in paint? Rectangle rect =NewRectangle (Ten,Ten, -, -);//defines the rectangle, with the parameter as the starting horizontal ordinate and its length and width//Monochrome FillSolidBrush B1 =NewSolidBrush (Color.Blue);//defining a monochrome paint brushG.fillrectangle (B1, rect);//Fill this rectangle//stringg.DrawString ("string",NewFont ("Song Body",Ten), B1,NewPointF ( -,Ten)); //Fill with picturesTextureBrush B2 =NewTextureBrush (Image.FromFile (@"D:\DOWNLOAD\sample.jpg")); Rect. Location=NewPoint (Ten, -);//change the start coordinate of this rectangleRect. Width = $;//Change the width of this rectangleRect. Height = $;//Change the height of this rectangleG.fillrectangle (B2, rect); //fill with gradient colorRect. Location =NewPoint (Ten,290); //A using System.Drawing.Drawing2D is required;LinearGradientBrush B3 =NewLinearGradientBrush (Rect, Color.yellow, Color.Black, lineargradientmode.horizontal); G.fillrectangle (B3, rect);

Operating effect:

Third, the conversion of the Axis

The axes in WinForm are different from the plane right angle axes that we normally touch, the axes in the WinForm are exactly the opposite: the upper-left corner of the form is the origin (0,0), the horizontal to the left is X, and the vertical down is Y.

Next , let's do this by rotating the direction of the axis to draw a pattern of different angles , or by changing the position of the coordinate origin to balance the position of the axis .

Graphics g = This. CreateGraphics ();//not here in load, can it be in paint? //Monochrome FillPen p =NewPen (Color.Blue,1); //Change Axis Angle             for(intI=0;i< -; i++) {g.rotatetransform (i); //Rotation AngleG.drawline (P,0,0, -,0);         G.resettransform (); //Reply axis coordinates            }            //panning AxesG.translatetransform ( -, -); G.drawline (P,0,0, -,0);            G.resettransform (); //pan to the specified coordinates and then rotate in degreesG.translatetransform ( -, $);  for(intI=0;i<8; i++) {G.rotatetransform ( $); G.drawline (P,0,0, -,0); } g.dispose ();

Operating effect:

C # GDI + simple Drawing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.