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?