C # GDI + simple Drawing (i)

Source: Internet
Author: User
Recently, GDI + this thing contact more, also did some simple examples, such as drawing board, imitation QQ and so on.

The first contact this class, is because want to do the effect of imitation QQ. Skillfully very, learned how to do it after that. NET classroom teacher also happened to talk about C # drawing knowledge, and I myself on the internet to learn the teacher's training, but also to use this class. There are some experiences in learning, so prepare to write down these experiences, because the content is more, perhaps I will be written several times.

Needless to say, let's meet this GDI + and see what it looks like.

Gdi+:graphics device Interface Plus is a graphics device interface that provides a rich array of graphics and image processing capabilities in C #. NET, using GDI + to process two-dimensional (2D) graphics and images, using DirectX to process a three-dimensional (3D) graphic image, the primary namespace used for graphic image processing is system. Drawing: Provides access to GDI + basic graphics features such as the Graphics class, the bitmap class, classes inherited from the brush class, the font class, the icon class, the image class, the pen class, the color class, and so on.

Probably understand what is GDI +, we look at the main tools to use the drawing, to draw, it must be the artboard, in C # in the artboard can be created through the graphics class, with the artboard, must get a pen what kind of bar, or how to draw, it is difficult for us to use finger painting. Pens can be divided into many kinds , such as pencils, brushes and so on. They are the main difference is the pencil can be used to draw lines, and painting brush, hey, I think about it. In C # We can use the Pen,brush class to achieve similar functionality. Pigments are naturally used in color classes.

With the tools, we can get started! (Required namespace: using System.Drawing;)

Achieve effect: Draw basic graphics in a blank form

First, prepare an artboard:
There are 3 main ways of creating an artboard:
A: Directly referencing a Graphics object in the Paint event of a form or control
B: Using the CreateGraphics method of a form or a control
C: Create a Graphics object from any object that inherits from the image
This time we'll start with a as an example to illustrate the problem:

private void Form1_paint (object sender, PaintEventArgs e)        {            Graphics g = e.graphics;//Create Artboards, where the artboard is provided by the form.        }

Then we want a pen:

private void Form1_paint (object sender, PaintEventArgs e)        {            Graphics g = e.graphics;//Create Artboards, where the artboard is provided by the form.            Pen p = new Pen (color.blue, 2);//defines a blue, width-wide brush        }

Then we'll be able to draw.

private void Form1_paint (object sender, PaintEventArgs e)        {            Graphics g = e.graphics;//Create Artboards, where the artboard is provided by the form.            Pen p = new Pen (color.blue, 2);//defines a blue, width-wide brush            g.drawline (p, 10, 10, 100, 100),//Draws a line on the artboard, the starting coordinate is (10,10), and the end coordinate is ( 100,100)            G.drawrectangle (p, 10, 10, 100, 100);//Draw a rectangle on the artboard with a starting coordinate of (10,10) and a width of            g.drawellipse (p, 10, 10, 100, 100) ;//Draw an ellipse on the artboard with the starting coordinate (10,10) and the width of the bounding rectangle as high as        }


As follows:




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.