本文整理汇总了C#中System.Drawing.StringFormat类的典型用法代码示例。如果您正苦于以下问题:C# StringFormat类的具体用法?C# StringFormat怎么用?C# StringFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringFormat类属于System.Drawing命名空间,在下文中一共展示了StringFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WaterMarkerImage
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Method to watermark image
/// </summary>
///
/// <remarks> Ken Hofgesang, 5/7/2012 </remarks>
///
/// <param name="ImgPath"> Path for Source Image. </param>
/// <param name="watermark"> String for watermark information. </param>
////////////////////////////////////////////////////////////////////////////////////////////////////
public static Bitmap WaterMarkerImage(string ImgPath, string watermark)
{
Bitmap bmp;
bmp = new Bitmap(ImgPath);
Graphics graphicsObject;
int x, y;
try
{
//Create graphics object from bitmap
graphicsObject = Graphics.FromImage(bmp);
}
catch (Exception e)
{
//Initilize new Bitmap for watermark info
Bitmap bmpNew = new Bitmap(bmp.Width, bmp.Height);
graphicsObject = Graphics.FromImage(bmpNew);
graphicsObject.DrawImage(bmp, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);
bmp = bmpNew;
}
//Adjust font size based on original image size and the length of watermark text
int startsize = (bmp.Width / watermark.Length);
//x and y cordinates to draw watermark string
x = 0;
y = bmp.Height / 4;
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.NoWrap);
//Draw watermark on Image
graphicsObject.DrawString(watermark, new Font("Times New Roman", startsize, FontStyle.Bold), new SolidBrush(Color.FromArgb(60, 255, 255, 255)), x, y, drawFormat);
//return Image
return (bmp);
}
示例2: BaseTextItem
public BaseTextItem():base() {
this.dataType = "System.String";
this.stringFormat = StringFormat.GenericTypographic;
this.contentAlignment = ContentAlignment.TopLeft;
this.stringTrimming = StringTrimming.None;
VisibleInReport = true;
}
示例3: EDSToolTip_Draw
void EDSToolTip_Draw(object sender, DrawToolTipEventArgs e)
{
if (e.ToolTipText.Trim() != "")
{
//e.DrawBackground();
Graphics g = e.Graphics;
//draw background
LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(Point.Empty, e.Bounds.Size), Color.FromArgb(250, 252, 253), Color.FromArgb(206, 220, 240), LinearGradientMode.Vertical);
g.FillRectangle(lgb, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
lgb.Dispose();
//Console.WriteLine(e.ToolTipText);
//draw border
ControlPaint.DrawBorder(g, e.Bounds, SystemColors.GrayText, ButtonBorderStyle.Dashed);
//draw Image
g.DrawImage(image, new Point(5, 5));
// Draw the custom text.
// The using block will dispose the StringFormat automatically.
using (StringFormat sf = new StringFormat())
{
using (Font f = new Font("Tahoma", 8))
{
e.Graphics.DrawString(e.ToolTipText, f,
Brushes.Black, e.Bounds.X + 25, e.Bounds.Y + 30, StringFormat.GenericTypographic);
}
}
}
}
示例4: Text
public void Text(string text, Font font, uint argb, Rectangle rect, StringFormat format)
{
graphics.DrawString(
text, font,
new SolidBrush(argb.ToColor()),
rect, format);
}
示例5: DiffViewer
public DiffViewer(TaskScheduler scheduler, HeapRecording instance)
: base(scheduler)
{
InitializeComponent();
ListFormat = new StringFormat {
Trimming = StringTrimming.None,
FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox
};
Timeline.ItemValueGetter = GetBytesTotal;
Timeline.ItemValueFormatter = MainWindow.FormatSizeBytes;
Instance = instance;
if (Instance != null) {
Timeline.Items = Instance.Snapshots;
Instance.TracebacksFiltered += Instance_TracebacksFiltered;
ViewHistogramByModuleMenu.Enabled = ViewHistogramByFunctionMenu.Enabled = true;
ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = true;
ViewHistogramByNamespaceMenu.Enabled = ViewTreemapMenu.Enabled = true;
} else {
Timeline.Visible = false;
MainSplit.Height += Timeline.Bottom - MainSplit.Bottom;
ViewHistogramByModuleMenu.Enabled = ViewHistogramByFunctionMenu.Enabled = false;
ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = false;
ViewHistogramByNamespaceMenu.Enabled = ViewTreemapMenu.Enabled = false;
}
}
示例6: Print
/// <summary>
/// Print header
/// </summary>
/// <param name="g">Graphics object where the data will be drawn</param>
/// <param name="area">Area where to print</param>
/// <param name="columns">Columns</param>
public override void Print(Graphics g, ref RectangleF area, IList columns, int page)
{
StringFormat stringFormat;
float height;
stringFormat = new StringFormat(StringFormat.GenericDefault);
height = font.GetHeight(g);
// Write columns label
foreach (Column column in columns)
{
RectangleF rect;
stringFormat.Alignment = column.Alignment;
rect = new RectangleF(
column.X, area.Top,
column.Width, height);
g.DrawString(
column.Label,
font,
brush,
rect,
stringFormat);
}
// Draw separator line
g.DrawLine(pen, area.Left, area.Top + height + lineDistance, area.Right, area.Top + height + lineDistance);
area.Y += height + lineDistance * 2;
area.Height -= height + lineDistance * 2;
}
示例7: CreateNativeLabel
internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment,
CCVerticalTextAlignment vAlignment, string fontName,
float fontSize, CCColor4B textColor)
{
if (string.IsNullOrEmpty(text))
{
return new CCTexture2D();
}
var font = CreateFont (fontName, fontSize);
if (dimensions.Equals(CCSize.Zero))
{
CreateBitmap(1, 1);
var ms = _graphics.MeasureString(text, font);
dimensions.Width = ms.Width;
dimensions.Height = ms.Height;
}
CreateBitmap((int)dimensions.Width, (int)dimensions.Height);
var stringFormat = new StringFormat();
switch (hAlignment)
{
case CCTextAlignment.Left:
stringFormat.Alignment = StringAlignment.Near;
break;
case CCTextAlignment.Center:
stringFormat.Alignment = StringAlignment.Center;
break;
case CCTextAlignment.Right:
stringFormat.Alignment = StringAlignment.Far;
break;
}
switch (vAlignment)
{
case CCVerticalTextAlignment.Top:
stringFormat.LineAlignment = StringAlignment.Near;
break;
case CCVerticalTextAlignment.Center:
stringFormat.LineAlignment = StringAlignment.Center;
break;
case CCVerticalTextAlignment.Bottom:
stringFormat.LineAlignment = StringAlignment.Far;
break;
}
_graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat);
_graphics.Flush();
var texture = new CCTexture2D();
texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444);
return texture;
}
示例8: Draw
/// <summary>
/// Draws the Card at its location
/// </summary>
/// <param name="g">The Graphics object to draw on</param>
public override void Draw(Graphics g)
{
Color colour = this.GetColor();
g.FillRectangle(new SolidBrush(colour), _rekt); // Fill
if (Selected)
{
g.DrawRectangle(new Pen(Brushes.Black, 2), _rekt); // Draw outline
}
else
{
g.DrawRectangle(new Pen(Brushes.White, 4), _rekt); // White 4pt
g.DrawRectangle(new Pen(Brushes.Black, 1), _rekt); // Black border 1pt
}
// The number
int fontHeight = _rekt.Height / 4;
Font arial = new Font("Arial", fontHeight, FontStyle.Bold);
// Fancy Centering
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
g.DrawString(this.Value.ToString(), arial, Brushes.Black, _rekt, stringFormat); // Black text (the number)
}
示例9: OnDrawItem
/// <summary>Override for the drawing of the control to include a Close Tab button</summary>
/// <param name="e"></param>
protected override void OnDrawItem(DrawItemEventArgs e)
{
RectangleF tabTextArea = RectangleF.Empty;
for(int nIndex = 0 ; nIndex < this.TabCount ; nIndex++)
{
tabTextArea = (RectangleF)this.GetTabRect(nIndex);
using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].BackColor))
{
//Clear the tab
e.Graphics.FillRectangle(brush, tabTextArea);
}
Bitmap bmp = nIndex == this.SelectedIndex ? Resources.activeClose : Resources.inactiveClose;
e.Graphics.DrawImage(bmp, tabTextArea.X + tabTextArea.Width - (CLOSE_ICON_PADDING + CLOSE_ICON_SIZE), tabTextArea.Y + CLOSE_ICON_PADDING, CLOSE_ICON_SIZE, CLOSE_ICON_SIZE);
bmp.Dispose();
string str = this.TabPages[nIndex].Text;
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].ForeColor))
{
//Draw the tab header text
e.Graphics.DrawString(str, this.Font, brush, tabTextArea,stringFormat);
}
}
}
示例10: GetEyeOfSightImage
private static Bitmap GetEyeOfSightImage()
{
var roestte = new Bitmap(120, 120);
//Anyone for a more sophisticated roestte?
using (var g = Graphics.FromImage(roestte))
{
var t = new Matrix(1f, 0f, 0f, 1f, 60, 60);
g.Transform = t;
var f = new Font("Arial", 20, FontStyle.Bold);
var b = new SolidBrush(Color.Black);
var p = new Pen(Color.Black, 5);
var sf = new StringFormat(StringFormat.GenericTypographic) {Alignment = StringAlignment.Center};
var rect = new RectangleF(- 45f, - 45f, 90f, 90f);
foreach (var s in Directions)
{
g.DrawString(s, f, b, 0, -55, sf);
g.DrawArc(p, rect, 290f, 50f);
g.RotateTransform(90f);
}
}
return roestte;
}
示例11: RepertoryImage
public static void RepertoryImage(Graphics drawDestination)
{
StringFormat itemStringFormat = new StringFormat();
RectangleF itemBox = new RectangleF(10, 30, 42, 10);
RectangleF itemBox2 = new RectangleF(60, 48, 10, 10);
itemStringFormat.Alignment = StringAlignment.Center;
itemStringFormat.LineAlignment = StringAlignment.Far;
drawDestination.DrawLine(Pens.LightGray,10,10,10,70);
if (mMscStyle == MscStyle.SDL){
PointF[] capPolygon = new PointF[3];
capPolygon[0] = new PointF(61, 40);
capPolygon[1] = new PointF(53, 44);
capPolygon[2] = new PointF(53, 36);
drawDestination.FillPolygon(Brushes.Black,capPolygon);
drawDestination.DrawString("Lost",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
drawDestination.DrawString("g",new Font("Arial",8),Brushes.Black,itemBox2,itemStringFormat);
drawDestination.DrawLine(Pens.Black,10, 40, 60,40);
drawDestination.FillEllipse(Brushes.Black, new RectangleF(60,35, 10,10));
}
else if(mMscStyle == MscStyle.UML2){
drawDestination.DrawString("Lost",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
drawDestination.DrawString("g",new Font("Arial",8),Brushes.Black,itemBox2,itemStringFormat);
drawDestination.DrawLine(Pens.Black,10, 40, 60,40);
drawDestination.DrawLine(Pens.Black,60, 40, 54,43);
drawDestination.DrawLine(Pens.Black,60, 40, 54,37);
drawDestination.FillEllipse(Brushes.Black, new RectangleF(60,35, 10,10));
}
itemStringFormat.Dispose();
}
示例12: DrawMenuItem
/// <summary>
/// �������˵���
/// </summary>
public static void DrawMenuItem(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi)
{
if ( (e.State & DrawItemState.HotLight) == DrawItemState.HotLight )
{
DrawHoverRect(e, mi);
}
else if ( (e.State & DrawItemState.Selected) == DrawItemState.Selected )
{
DrawSelectionRect(e, mi);
}
else
{
Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width,
e.Bounds.Height -1);
e.Graphics.FillRectangle(new SolidBrush(Globals.MainColor), rect);
e.Graphics.DrawRectangle(new Pen(Globals.MainColor), rect);
}
StringFormat sf = new StringFormat();
//�������־���
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
//��������
e.Graphics.DrawString(mi.Text,
Globals.menuFont,
new SolidBrush(Globals.TextColor),
e.Bounds,
sf);
}
示例13: DrawString
public abstract void DrawString(
string s,
Font font,
Brush brush,
RectangleF layoutRectangle,
StringFormat format
);
示例14: SnakePit
public SnakePit()
{
this.screen = DeviceGraphics.GetScreen();
this.screen.Clear(Color.White);
this.numCellsX = (DeviceGraphics.ScreenXSize / cellSize) - 2;
this.numCellsY = ((DeviceGraphics.ScreenYSize - scoreBoardHeight) / cellSize) - 2;
this.cellOfsX = cellSize;
this.cellOfsY = cellSize;
this.rnd = new Random();
this.food = null;
this.score = 0;
this.level = 1;
using (Brush brush = new HatchBrush(HatchStyle.DiagonalCross, Color.Black, Color.White)) {
this.screen.FillRectangle(brush, 0, 0, DeviceGraphics.ScreenXSize, cellSize);
this.screen.FillRectangle(brush, 0, cellSize, cellSize, this.numCellsY * cellSize);
this.screen.FillRectangle(brush, (1 + this.numCellsX) * cellSize, cellSize, cellSize, this.numCellsY * cellSize);
this.screen.FillRectangle(brush, 0, (1 + this.numCellsY) * cellSize, DeviceGraphics.ScreenXSize, cellSize);
}
this.screen.DrawRectangle(Pens.Black, cellSize - 1, cellSize - 1,
this.numCellsX * cellSize + 1, this.numCellsY * cellSize + 1);
using (Font f = new Font("tahoma", 15)) {
using (StringFormat sf = new StringFormat()) {
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
this.screen.DrawString("<", f, Brushes.Black, new RectangleF(0, 220, 64, 20), sf);
this.screen.DrawString("v", f, Brushes.Black, new RectangleF(64, 220, 64, 20), sf);
this.screen.DrawString("^", f, Brushes.Black, new RectangleF(128, 220, 64, 20), sf);
this.screen.DrawString(">", f, Brushes.Black, new RectangleF(192, 220, 64, 20), sf);
}
}
this.ShowScore();
}
示例15: TextBoxTextRenderer
static TextBoxTextRenderer ()
{
// On Windows, we want to use TextRenderer (GDI)
// On Linux, we want to use DrawString (GDI+)
// TextRenderer provides translation from TextRenderer to
// DrawString, but I doubt it's exact enough.
// Another option would be to put Pango here for Linux.
int platform = (int)Environment.OSVersion.Platform;
if (platform == 4 || platform == 128 || platform == 6)
use_textrenderer = false;
else
use_textrenderer = true;
// windows 2000 doesn't draw with gdi if bounds are In32.MaxValue
max_size = new Size (Int16.MaxValue, Int16.MaxValue);
sf_nonprinting = new StringFormat (StringFormat.GenericTypographic);
sf_nonprinting.Trimming = StringTrimming.None;
sf_nonprinting.FormatFlags = StringFormatFlags.DisplayFormatControl;
sf_nonprinting.HotkeyPrefix = HotkeyPrefix.None;
sf_printing = StringFormat.GenericTypographic;
sf_printing.HotkeyPrefix = HotkeyPrefix.None;
measure_cache = new Hashtable ();
}