C # GDI + simple plotting (1)

Source: Internet
Author: User
Latest pair GDI + This item has many contacts and some simple examples, such as drawing board and Imitation Qq And so on.

I first came into contact with this class because I wanted to copy it.QqAfter learning how to do it,. NetThe teacher is about to talk aboutC #Drawing knowledge, and I have learned the training courses of instructor Jin on the Internet, I also want to use this class. I have some experience in learning, so I want to write down these experiences. Because there are many content, I may write it several times.

Let's get to know this.GDI +To see what it looks like..

GDI + : Graphics Device Interface plus That is, the graphic device interface. , Provides a variety of graphic image processing functions ; In C #. net , Use GDI + Processing two-dimensional ( 2d ). DirectX Processing 3D ( 3D ). , The main namespace used for image processing is System. Drawing : Provides GDI + Access to basic graphic functions mainly includes Graphics Class, Bitmap Class, slave Brush Class inherited class, Font Class, Icon Class, Image Class, Pen Class, Color Class .

What is GDI + After , Let's take a look at the main tools used for plotting. , Drawing , YesCanvasRight , In C # You can use Graphics This class is used to create , With the canvas , Always get onePenWhat? , Otherwise, why? , It's hard. . Pen can be divided into many types , For example, pencil , Image painter . Their main difference is that pencils can be used to draw lines. , What about image painter? , Hey , Consider it yourself . In C # We can use Pen, brush Class to implement similar functions . Pigments are used naturally. Color Class .

With tools,Let's get started.! (Required namespace: using system. Drawing ;)

Effect:Draw a basic image in a blank form

First Prepare a canvas :
Creating an artboard mainly includes 3 Method :
A: In Paint Direct reference in the event Graphics Object
B: Using a form or a widget's Creategraphics Method
C: Create from any object inherited from the image Graphics Object
This time, we will start A For example, describe the problem :

  Private   Void Form1_paint ( Object Sender, painteventargs E)
{
Graphics g=E. graphics;//Create a canvas. The canvas here is provided by form.
}

Then,We only need a pen:

Private   Void Form1_paint ( Object Sender, painteventargs E)
{
Graphics g = E. graphics; // Create a canvas. The canvas here is provided by form.
Pen P =   New Pen (color. Blue, 2 ); // Defines a blue, width-based brush.
}

NextSo we can paint..

Private   Void Form1_paint ( Object Sender, painteventargs E)
{
Graphics g = E. graphics; // Create a canvas. The canvas here is provided by form.
Pen P =   New Pen (color. Blue, 2 ); // Defines a blue, width-based brush.
G. drawline (p, 10 , 10 , 100 , 100 ); // Draw a straight line on the drawing board. The starting coordinate is (10, 10), and the ending coordinate is (100,100)
G. drawrectangle (p, 10 , 10 , 100 , 100 ); // Draw a rectangle on the canvas. The start coordinate is (10, 10), the width is, and the height is
G. drawellipse (p, 10 , 10 , 100 , 100 ); // Draw an ellipse on the drawing board. The starting coordinate is (10, 10), the width of the external rectangle is, and the height is
}


As follows::

 

This filmArticleIn fact, I also posted a blog http://blog.54master.com/index.php/586951/ in my, but the continuous film has not been sent, do not know what's going on, so move to this, re-send!

 

Other links:

C # GDI + simple drawing (1): introduce the basic knowledge of GDI +

C # GDI + simple drawing (2): Introduce the knowledge of GDI + drawing

C # GDI + simple drawing (3): implement the QQ imitation Function

C # GDI + simple drawing (4): implement the windows-like drawing board Function

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.