MSDN上的解释:
在指定位置并且用指定的 Brush 和Font 对象绘制指定的文本字符串。
public void DrawString(string s,Font font,Brush brush,float x,float y)
MSDN上的实例:
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 = 150.0F; float y = 150.0F;// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y);
}
应用的实例:
private void Myprintpage1(Graphics formGraphics, int w, int h) {
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(100.0F, 50.0F); //画表格横线
//画表格竖线
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)); }
//画表格斜线 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)); //写字 formGraphics.DrawString(" —数据报表—", new Font("宋体", 20, FontStyle.Bold), Brushes.DimGray, 100, -10);
formGraphics.DrawString("试验日期(Date) :_______________", MyFont1, Brushes.DimGray, 0, 50); formGraphics.DrawString("操作人员(Operator):_______________", MyFont1, Brushes.DimGray, 0, 75);
formGraphics.DrawString("试件类型(Parts Type):_______________", MyFont1, Brushes.DimGray, 330, 50); formGraphics.DrawString("试件编号(Parts No):_______________", MyFont1, Brushes.DimGray, 330, 75);
formGraphics.DrawString("上号(UP):_______________", MyFont1, Brushes.DimGray, 0, 100); formGraphics.DrawString("下号(DOWN):_______________", MyFont1, Brushes.DimGray, 330, 100);
formGraphics.DrawString("电压", MyFont1, Brushes.DimGray, 190, 220);
//formGraphics.DrawString(" (Forward Speed)", MyFont2, Brushes.DimGray, 300, 110); formGraphics.DrawString("电流", MyFont1, Brushes.DimGray, 340, 220);
可以有一个人陪着你,也可以你一个人,总之那一刻,