Graphics. drawstring Method

Source: Internet
Author: User

Description on msdn:

Draws the specified text string at the specified position with the specified brush and font object.

public void DrawString(string s,Font font,Brush brush,float x,float y)

Msdn instances:

Public void drawstringfloat (painteventargs E)

{

// Create string to draw

. String drawstring = "sample text"; // create font and brush.

Font drawfont = new font ("Arial", 16 );

Solidbrush drawbrush = new solidbrush (color. Black); // create point for upper-left corner of drawing.

Float x = 1500000f; float y = 1500000f; // draw string to screen.

E. Graphics. drawstring (drawstring, drawfont, drawbrush, x, y );

}

Application instance:

Private void myprintpage1 (Graphics formgraphics, int W, int h) // Function
{

Pen mypen = new pen (color. fromargb (255, color. Black), 1.0f );
Font myfont1 = new font ("", 12, fontstyle. Bold );
Font myfont2 = new font ("", 10, fontstyle. Bold );

Formgraphics. translatetransform (100366f, 50366f );
// Draw the horizontal line of the table


// Draw a table vertical line

For (INT I = 200; I <360; I + = 50)
{
Formgraphics. drawline (mypen, new point (0, I), new point (600, I ));
Formgraphics. drawline (mypen ,)
}

For (INT I = 0; I <750; I + = 150)
{
Formgraphics. drawline (mypen, new point (I, 200), new point (I, 350 ));
}

// Draw a table diagonal line
Formgraphics. drawline (mypen, new point (0,200), new point (150,250 ));
// Formgraphics. drawline (mypen, new point (150,125), new point (300,125 ));
// Formgraphics. drawline (mypen, new point (150,175), new point (300,175 ));
// Write
Formgraphics. drawstring ("--- data report ---", new font ("", 20, fontstyle. Bold), brushes. dimgray, 100,-10 );

Formgraphics. drawstring ("test date): _______________", myfont1, brushes. dimgray, 0, 50 );
Formgraphics. drawstring ("operator): _______________", myfont1, brushes. dimgray, 0, 75 );

Formgraphics. drawstring ("specimen type (Parts type): ___________", myfont1, brushes. dimgray, 330, 50 );
Formgraphics. drawstring ("specimen no (parts no): ___________", myfont1, brushes. dimgray, 330, 75 );

Formgraphics. drawstring ("train number (up): _______________", myfont1, brushes. dimgray, 0,100 );
Formgraphics. drawstring ("down (down): _______________", myfont1, brushes. dimgray, 330,100 );

// Formgraphics. drawstring ("main duct 5 min", myfont1, brushes. dimgray, 180,108 );
Formgraphics. drawstring ("voltage", myfont1, brushes. dimgray, 190,220 );

// Formgraphics. drawstring ("(forward speed)", myfont2, brushes. dimgray, 300,110 );
Formgraphics. drawstring ("current", myfont1, brushes. dimgray, 340,220 );

// Formgraphics. drawstring ("(backward speed)", myfont2, brushes. dimgray, 455,110 );
Formgraphics. drawstring ("standby", myfont1, brushes. dimgray, 490,220 );

Formgraphics. drawstring ("test data (date)", myfont1, brushes. dimgray, 0,270 );
Formgraphics. drawstring ("unit", myfont1, brushes. dimgray, 0,320 );

Formgraphics. drawstring ("operator): _______________ Checker: _______________", myfont1, brushes. dimgray, 0,970 );

Formgraphics. drawstring (datetime. Now. tostring ("yyyy/mm/DD"), myfont1, brushes. dimgray, 180, 50 );
Formgraphics. drawstring (Global. temstr [0], myfont1, brushes. dimgray, 180, 75 );
Formgraphics. drawstring (Global. temstr [2], myfont1, brushes. dimgray, 510, 50 );
Formgraphics. drawstring (Global. temstr [1], myfont1, brushes. dimgray, 510, 75 );

Formgraphics. drawstring (Global. temstr [3], myfont1, brushes. dimgray, 180,100 );
Formgraphics. drawstring (Global. temstr [4], myfont1, brushes. dimgray, 500,100 );

Formgraphics. drawstring ("", myfont1, brushes. dimgray, 190,270 );//
Formgraphics. drawstring ("", myfont1, brushes. dimgray, 340,270 );//
Formgraphics. drawstring ("", myfont1, brushes. dimgray, 490,270 );

 

Formgraphics. drawstring ("V", myfont1, brushes. dimgray, 190,320 );

Formgraphics. drawstring ("A", myfont1, brushes. dimgray, 340,320 );

Formgraphics. drawstring ("", myfont1, brushes. dimgray, 490,320 );

}

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.