C # GDI + simple Drawing (ii)

Source: Internet
Author: User

In the previous piece has been introduced to you how to use GDI + to draw a simple image, this piece continues to introduce some other drawing knowledge.

1. First, let's look at the pen we used in the last piece.

Pen properties are mainly: color (color), dashcap (dash End shape), dashstyle (dotted style), endcap (line End shape), startcap (thread shape), Width (thickness), and so on.

We can use pen to draw dashes, lines with arrows, etc.

Pen p = new Pen(Color.Blue, 5);//设置笔的粗细为,颜色为蓝色
Graphics g = this.CreateGraphics();
//画虚线
p.DashStyle = DashStyle.Dot;//定义虚线的样式为点
g.DrawLine(p, 10, 10, 200, 10);
//自定义虚线
p.DashPattern = new float[] { 2, 1 };//设置短划线和空白部分的数组
g.DrawLine(p, 10, 20, 200, 20);
//画箭头,只对不封闭曲线有用
p.DashStyle = DashStyle.Solid;//恢复实线
p.EndCap = LineCap.ArrowAnchor;//定义线尾的样式为箭头
g.DrawLine(p, 10, 30, 200, 30);
g.Dispose();
p.Dispose();

The above code runs the result:

2. Next, let's take a look at the use of brush.

Role: We can use brush to fill a variety of graphic shapes, such as rectangles, ellipses, fans, polygons and closed paths, and so on, there are several different types of painting brushes:

SolidBrush: The simplest form of a brush, drawing with a solid color

HatchBrush: Similar to SolidBrush, but you can use this class to select from a large number of preset patterns to use when drawing, instead of a solid color

TextureBrush: Drawing with textures (such as images)

LinearGradientBrush: Draw with two colors that blend along the gradient

PathGradientBrush: A unique path based on the programmer definition, drawing with a complex blend color gradient

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.