Analysis on Graph programming in C #

Source: Internet
Author: User

Like Java, C # provides a rich set of class libraries, methods, and events for developers to use. C # also introduces GDI +, which evolved from GDI, which has more powerful functions than GDI and simplifies programming for programmers. Therefore, developers can easily develop applications with powerful graphic and image functions. In this article, I will introduce the basic knowledge of graph programming in C # through some examples.


Simple Example:

First, let's start with an example. The following is the simplest example:

Using System;

Using System. Windows. Forms;

Using System. Drawing;


Public class Hello: Form {

Public Hello (){

This. Paint + = new PaintEventHandler (f1_paint );

}


Private void f1_paint (object sender, PaintEventArgs e ){

Graphics g = e. Graphics;

G. DrawString ("Hello, C #! ", New Font (" Verdana ", 20 ),

New SolidBrush (Color. Tomato), 40, 40 );

G. DrawRectangle (new Pen (Color. Pink, 3), 150,100 );

}


Public static void Main (){

Application. Run (new Hello ());

}

}

In the above example, we used a method: DrawString (), which contains five parameters. At the same time, we found that before using the DrawString () method, we first created a Graphics type object g = e. graphics, which indicates that before using any method of the graphic class, we must first create an instantiated object of this class. After the DrawString () method, we used the DrawRectangle () method. In fact, we can also use other methods to draw an elliptical or polygon. The first instance is quite easy to understand, isn't it?

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.