Examples of drawing with GDI

Source: Internet
Author: User

Today, I learned a small example of using GDI to draw images, which makes a small foreshadowing for the future study of GDI.

Using system;
Using system. drawing;
Using system. Windows. forms;
Using system. Drawing. drawing2d;

Namespace GDI _
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}


Private pointf (int p, int p_2)
{
Throw new notimplementedexception ();
}

Private void form=mousemove (Object sender, mouseeventargs E)
{
// Obtain the desktop coordinates
This. Text = string. Format ("x = {0}, y = {1}", E. X, E. y );
}

Private void button#click (Object sender, eventargs E)
{
Drawimage = new drawimage ();
Drawimage. OBJ = rtb_image.creategraphics ();
Drawimage. Draw ();
}

Private void textbox1_textchanged (Object sender, eventargs E)
{

}
}
Public class drawimage
{

// Attributes
/// <Summary>
/// This attribute is used to obtain different graphics objects (initial image 600*385)
/// </Summary>
Public graphics OBJ
{
Get;
Set;
}
// Drawing Method
Public void draw ()
{
Font font = new font ("", 9 );
// Determine the drawing path. The test is performed here.
Graphicspath gpath = new graphicspath ();
// Monthly profit data
Double [] DATA = {34.3, 65.7, 33.1, 87, 57.3, 56, 99, 56.3, 41.6, 48.1, 57.3 };
// Store the coordinates of the highest profit data point of each month
Pointf [] dotp = new system. Drawing. pointf [12];
// Fixed origin coordinates are not modified
Point O = new point (1, 35,350 );
// Redefine a pen with a front arrow
Pen = new pen (color. Red );
Pen. endcap = system. Drawing. drawing2d. linecap. arrowanchor;
// Create a graphics object
Graphics G = OBJ;
// Origin ID
G. drawstring ("O", Font, brushes. Black, O. X-5, O. Y + 5 );
// Draw the X axis
G. drawline (pen, o. x, O. Y, o. x + 550, O. Y );
// Draw the Y axis
G. drawline (pen, o. x, O. Y, o. x, O. Y-325 );
// Draw the X axis Scale (X, Y + 5) and month
For (INT I = 0; I <12; I ++)
{
G. drawline (pens. red, O. X + (I + 1) * 42, O. y, O. X + (I + 1) * 42, O. y-5 );
// Determine the month coordinates
Pointf monp = new system. Drawing. pointf (O. X + (I + 1) * 42-10, O. Y + 5 );
G. drawstring (string. Format ("{0} month", I + 1), Font, brushes. Green, monp );
// Determine the maximum profit point coordinates of each month
Pointf mofpp = new pointf (monp. X, O. Y-(float) data [I] * 3 );
Dotp [I] = mofpp;
// G. drawellipse (pens. seagreen, new rectanglef (mofpp. X, mofpp. Y, 2, 2 ));
Gpath. addellipse (New rectanglef (mofpp. X, mofpp. Y, 2, 2 ));
}
Gpath. addlines (dotp );
G. drawpath (pens. Purple, gpath );
// G. drawlines (pens. Plum, dotp );
// Draw Y axis coordinates (x, Y-5), profit 10 W = 30px ==> 1 W = 3px
For (INT I = 0; I <10; I ++)
{
G. drawline (pens. red, O. x, O. y-(I + 1) * 30, O. X + 5, O. y-(I + 1) * 30 );
// Determine the amount Coordinate
Pointf payp = new pointf (O. X-35, O. Y-(I + 1) * 30-8 );
G. drawstring (string. Format ("{0} million", (I + 1) * 10), Font, brushes. Green, payp );
}
Pen. Dispose (); // release the created pen object.
}
}
}

:

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.