本文整理汇总了C#中Graphics.DrawString方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.DrawString方法的具体用法?C# Graphics.DrawString怎么用?C# Graphics.DrawString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graphics
的用法示例。
在下文中一共展示了Graphics.DrawString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// ExStart:AddWatermarkToImage
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();
// Create an instance of Image and load an existing image
using (Image image = Image.Load(dataDir + "WaterMark.bmp"))
{
// Create and initialize an instance of Graphics class
Graphics graphics = new Graphics(image);
// Creates an instance of Font
Font font = new Font("Times New Roman", 16, FontStyle.Bold);
// Create an instance of SolidBrush and set its various properties
SolidBrush brush = new SolidBrush();
brush.Color = Color.Black;
brush.Opacity = 100;
// Draw a String using the SolidBrush object and Font, at specific Point and Save the image with changes.
graphics.DrawString("Aspose.Imaging for .Net", font, brush, new PointF(image.Width / 2, image.Height / 2));
image.Save(dataDir + "AddWatermarkToImage_out.bmp");
// ExStart:AddWatermarkToImage
// Display Status.
Console.WriteLine("Watermark added successfully.");
}
}
示例2: CustomPaint
protected override void CustomPaint(Graphics g)
{
if (Text.Length == 0)
{
g.DrawString(HintText, Font, _hintBrush, HintOffset);
}
}
示例3: drawByStringFormat
protected void drawByStringFormat(Graphics graphics)
{
Rectangle cr = this.ClientRectangle;
Brush brush = new SolidBrush(this.ForeColor);
graphics.DrawString("�»��", this.Font, brush, cr.Left, cr.Top);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Far;
graphics.DrawString("���ϴ�", this.Font, brush, cr.Right, cr.Bottom, sf);
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
graphics.DrawString("��Ȯ�� �߾�?", this.Font, brush, cr.X + cr.Width/2, cr.Y+cr.Height/2, sf);
}
示例4: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
G = e.Graphics;
Rect = e.Bounds;
using (SolidBrush Back = new SolidBrush(Color.FromArgb(34, 34, 33)))
{
G.FillRectangle(Back, new Rectangle(e.Bounds.X - 4, e.Bounds.Y - 1, e.Bounds.Width + 4, e.Bounds.Height + 1));
}
if (!(e.Index == -1))
{
using (Font ItemsFont = new Font("Segoe UI", 9))
{
using (Pen Border = new Pen(Color.FromArgb(38, 38, 37)))
{
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
using (SolidBrush HoverItemBrush = new SolidBrush(Color.FromArgb(220, 220, 220)))
{
using (SolidBrush HoverItemFill = new SolidBrush(Color.FromArgb(38, 38, 37)))
{
G.FillRectangle(HoverItemFill, new Rectangle(Rect.X - 1, Rect.Y + 2, Rect.Width + 1, Rect.Height - 4));
G.DrawString(GetItemText(Items[e.Index]), new Font("Segoe UI", 9), HoverItemBrush, new Point(Rect.X + 5, Rect.Y + 1));
}
}
}
else
{
using (SolidBrush DefaultItemBrush = new SolidBrush(Color.FromArgb(220, 220, 220)))
{
G.DrawString(GetItemText(Items[e.Index]), new Font("Segoe UI", 9), DefaultItemBrush, new Point(Rect.X + 5, Rect.Y + 1));
}
}
}
}
}
base.OnDrawItem(e);
}
示例5: drawByMeasureString
protected void drawByMeasureString(Graphics graphics)
{
Rectangle cr = this.ClientRectangle;
string s = "���߾�";
SizeF textSize = graphics.MeasureString(s, this.Font);
graphics.DrawString(s, this.Font, new SolidBrush(this.ForeColor),
cr.X+cr.Width/2-textSize.Width/2,
cr.Y+cr.Height/2-textSize.Height/2);
}
示例6: CenterString
public static void CenterString(Graphics G, string T, Font F, Color C, Rectangle R)
{
SizeF TS = G.MeasureString(T, F);
using (SolidBrush B = new SolidBrush(C))
{
G.DrawString(T, F, B, new Point(R.Width / 2 - (((int)TS.Width) / 2), ((int)R.Height) / 2 - (((int)TS.Height) / 2)));
}
}
示例7: drawObject
public static void drawObject(Graphics g, ObjectRec curObject, bool isSelected, float curScale, ImageList objectSprites)
{
//don't render commands
if (curObject.type >= 0xFF00)
return;
var dict = curObject.additionalData;
var myFont = new Font(FontFamily.GenericSansSerif, 6.0f);
int x = curObject.x, y = curObject.y;
int addX = dict["addX"];
int addY = dict["addY"];
int fromFloor = dict["fromFloor"];
/*if (curObject.type < objectSprites.Images.Count)
{
var p1 = new Point((int)(x * curScale) - 8, (int)(y * curScale) - 8);
var p2 = new Point(p1.X + (int)(addX/2 * curScale) - 8, p1.Y + (int)(addY/2 * curScale) - 8);
g.DrawImage(objectSprites.Images[curObject.type], p1);
if (fromFloor == 0)
{
g.DrawImage(objectSprites.Images[curObject.type],p2);
g.DrawLine(new Pen(Brushes.Red), p1, p2);
}
}
else*/
{
var p1 = new Point((int)(x * curScale) - 8, (int)(y * curScale) - 8);
g.FillRectangle(Brushes.Black, new Rectangle(p1, new Size(16, 16)));
g.DrawString(curObject.type.ToString("X3"), myFont, Brushes.White, p1);
if (fromFloor == 0)
{
var p2 = new Point(p1.X + (int)(addX/2 * curScale) - 8, p1.Y + (int)(addY/2 * curScale) - 8);
g.FillRectangle(Brushes.Green, new Rectangle(p2, new Size(16, 16)));
g.DrawString(curObject.type.ToString("X3"), myFont, Brushes.White, p2);
g.DrawLine(new Pen(Brushes.Red), p1, p2);
}
}
if (isSelected)
g.DrawRectangle(new Pen(Brushes.Red, 2.0f), new Rectangle((int)(x * curScale) - 8, (int)(y * curScale) - 8, 16, 16));
}
示例8: DrawText
public static void DrawText(Graphics graphics, string text, string fontFamily
, float fontSize, FontStyle style, Brush color, Point position)
{
Font font = new Font(fontFamily, fontSize, style);
SizeF textSizeF = graphics.MeasureString(text, font);
int width = (int)Math.Ceiling(textSizeF.Width);
int height = (int)Math.Ceiling(textSizeF.Height);
Size textSize = new Size(width, height);
Rectangle rectangle = new Rectangle(position, textSize);
graphics.DrawString(text, font, color, rectangle);
}
示例9: DrawTestString
static void DrawTestString (Graphics g, GraphicsUnit unit)
{
g.PageUnit = unit;
float left = 50;
float top = 50;
float height = 10;
g.DrawLine (Pens.Black, left, top, left, top + height);
g.DrawLine (Pens.Black, left, top + height, left + height, top + height);
Font font = new Font ("Arial", height, unit);
g.DrawString ("Xyz| unit: " + unit.ToString (), font, Brushes.Black, left, top);
}
示例10: drawPoints
/// <summary>
/// Malt die Punkte auf dem Bildschirm auf
/// und beschriftet sie mit den Koordinaten
/// </summary>
/// <param name="gr">Graphics-Objekt, auf dem gezeichnet wird</param>
public void drawPoints(Graphics gr)
{
foreach(Point point in this.points) {
gr.DrawRectangle(Pens.Black,
point.x*SCALE_FACTOR,
point.y*SCALE_FACTOR,
.5f,
.5f);
//Punkte beschriften:
gr.DrawString("(" + point.x + "|" + point.y + ")",
new Font("Arial.ttf", 8, FontStyle.Bold),
Brushes.Black,
point.x*SCALE_FACTOR,
point.y*SCALE_FACTOR);
}
}
示例11: Run
public static void Run()
{
// ExStart:AddDiagonalWatermarkToImage
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();
// Load an existing JPG image
using (Image image = Image.Load(dataDir + "SampleTiff1.tiff"))
{
// Declare a String object with Watermark Text
string theString = "45 Degree Rotated Text";
// Create and initialize an instance of Graphics class and Initialize an object of SizeF to store image Size
Graphics graphics = new Graphics(image);
SizeF sz = graphics.Image.Size;
// Creates an instance of Font, initialize it with Font Face, Size and Style
Font font = new Font("Times New Roman", 20, FontStyle.Bold);
// Create an instance of SolidBrush and set its various properties
SolidBrush brush = new SolidBrush();
brush.Color = Color.Red;
brush.Opacity = 0;
// Initialize an object of StringFormat class and set its various properties
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
// Create an object of Matrix class for transformation
Matrix matrix = new Matrix();
// First a translation then a rotation
matrix.Translate(sz.Width / 2, sz.Height / 2);
matrix.Rotate(-45.0f);
// Set the Transformation through Matrix
graphics.Transform = matrix;
// Draw the string on Image Save output to disk
graphics.DrawString(theString, font, brush, 0, 0, format);
image.Save(dataDir + "AddDiagonalWatermarkToImage_out.jpg");
}
// ExStart:AddDiagonalWatermarkToImage
}
示例12: paint
public void paint(Graphics g)
{
int Xpos = (int)(xpos*TuioDemo.width);
int Ypos = (int)(ypos*TuioDemo.height);
int size = TuioDemo.height/10;
g.TranslateTransform(Xpos,Ypos);
g.RotateTransform((float)(angle/Math.PI*180.0f));
g.TranslateTransform(-1*Xpos,-1*Ypos);
g.FillRectangle(black, new Rectangle(Xpos-size/2,Ypos-size/2,size,size));
g.TranslateTransform(Xpos,Ypos);
g.RotateTransform(-1*(float)(angle/Math.PI*180.0f));
g.TranslateTransform(-1*Xpos,-1*Ypos);
Font font = new Font("Arial", 10.0f);
g.DrawString(symbol_id+"",font, white, new PointF(Xpos-10,Ypos-10));
}
示例13: CreateImage
public static void CreateImage (RotateFlipType rotate, int movex, int movey, string text, Bitmap dest, Graphics grdest)
{
Color clr;
Bitmap bmp = new Bitmap (80, 80, PixelFormat.Format32bppArgb);
Graphics gr = Graphics.FromImage (bmp);
gr.Clear (Color.White);
gr.DrawLine (p, 10.0F, 10.0F, 70.0F, 70.0F);
gr.DrawLine (p, 10.0F, 15.0F, 70.0F, 15.0F);
gr.DrawRectangle (p, 10.0F, 10.0F, 60.0F, 60.0F);
bmp.RotateFlip (rotate);
for (int y = 0; y < 80; y++) {
for (int x = 0; x < 80; x++) {
clr = bmp.GetPixel (x,y);
dest.SetPixel (x+movex, y+movey, clr);
}
}
grdest.DrawString (text, new Font ("Arial", 8), br, movex+5, movey+85);
}
示例14: renderObjects
public void renderObjects(Graphics g, int curScale)
{
for (int i = 0; i < 64; i++)
{
byte b1 = Globals.romdata[0x2BE4D + i*6];
byte b2 = Globals.romdata[0x2BE4D + i*6 + 1];
byte b3 = Globals.romdata[0x2BE4D + i*6 + 2];
byte b4 = Globals.romdata[0x2BE4D + i*6 + 3];
byte b5 = Globals.romdata[0x2BE4D + i*6 + 4];
byte b6 = Globals.romdata[0x2BE4D + i*6 + 5];
var rect = new Rectangle(32*curScale*(i+1), 8*32*curScale, 32*curScale*(i+2), (curScale*32*8)+80);
g.DrawRectangle(new Pen(Color.Red, 4.0f), rect);
g.DrawString(String.Format("{0:X2}", b1), new Font("Arial", 8), Brushes.Red, rect);
g.DrawString(String.Format("{0:X2}", b2), new Font("Arial", 8), Brushes.Red, rect.X + 16, rect.Y);
g.DrawString(String.Format("{0:X2}", b3), new Font("Arial", 8), Brushes.Red, rect.X + 32, rect.Y);
g.DrawString(String.Format("{0:X2}", b4), new Font("Arial", 8), Brushes.Red, rect.X + 0 , rect.Y+16);
g.DrawString(String.Format("{0:X2}", b5), new Font("Arial", 8), Brushes.Red, rect.X + 16, rect.Y+16);
g.DrawString(String.Format("{0:X2}", b6), new Font("Arial", 8), Brushes.Red, rect.X + 32, rect.Y+16);
}
}
示例15: OnPaint
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
G = e.Graphics;
G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
G.Clear(BackColor);
SZ1 = G.MeasureString(Value1, Font, Width, StringFormat.GenericTypographic);
SZ2 = G.MeasureString(Value2, Font, Width, StringFormat.GenericTypographic);
PT1 = new PointF(0, Height / 2 - SZ1.Height / 2);
PT2 = new PointF(SZ1.Width + 1, Height / 2 - SZ1.Height / 2);
G.DrawString(Value1, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
G.DrawString(Value1, Font, Brushes.White, PT1);
G.DrawString(Value2, Font, Brushes.Black, PT2.X + 1, PT2.Y + 1);
G.DrawString(Value2, Font, B1, PT2);
}