本文整理汇总了C#中System.Drawing.Font类的典型用法代码示例。如果您正苦于以下问题:C# Font类的具体用法?C# Font怎么用?C# Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Font类属于System.Drawing命名空间,在下文中一共展示了Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Text
public void Text(string text, Font font, uint argb, Rectangle rect, StringFormat format)
{
graphics.DrawString(
text, font,
new SolidBrush(argb.ToColor()),
rect, format);
}
示例2: PaintJunk
public void PaintJunk(Graphics g)
{
g.FillRectangle(Brushes.Transparent, 0, 0, 1000, 1000);
using (Font font = new Font("Courier New", 20, FontStyle.Bold))
{
if (bounceCounter == -1) return;
const string str = "DEVELOPER BUILD";
float x = 0;
int timefactor = bounceCounter;
for (int i = 0; i < str.Length; i++)
{
string slice = str.Substring(i, 1);
g.PageUnit = GraphicsUnit.Pixel;
x += g.MeasureString(slice, font).Width - 1;
int offset = -i * 3 + timefactor*3;
int yofs = 0;
if (offset < 0)
{ continue; }
else
if (offset < DigitTable.Length)
yofs = DigitTable[offset];
g.DrawString(slice, font, Brushes.Black, 5 + x, 15 - yofs);
}
}
}
示例3: GetCharacterSize
public virtual Size GetCharacterSize( Graphics g, Font font, CharacterCasing casing )
{
const int MeasureCharCount = 10;
Size charSize = new Size( 0, 0 );
for ( char c = '0'; c <= '9'; ++c )
{
Size newSize = TextRenderer.MeasureText( g, new string( c, MeasureCharCount ), font, new Size( 0, 0 ),
_textFormatFlags );
newSize.Width = (int)Math.Ceiling( (double)newSize.Width / (double)MeasureCharCount );
if ( newSize.Width > charSize.Width )
{
charSize.Width = newSize.Width;
}
if ( newSize.Height > charSize.Height )
{
charSize.Height = newSize.Height;
}
}
return charSize;
}
示例4: 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);
}
}
}
}
示例5: DrawStringML
private static void DrawStringML(this Graphics G, string Text, Font font, Brush brush, float x, ref float y, float mX)
{
string[] words = Text.Split(' ');
float tempX = x;
float totalSpace = mX - x;
SizeF measureWord = new SizeF(0, font.GetHeight());
float tempWordWidth = 0;
foreach (string word in words)
{
//measure word width (based in font size)
tempWordWidth = G.MeasureString(word + " ", font).Width;
measureWord.Width += tempWordWidth;
//check if the word fits in free line space
//if not then change line
if (measureWord.Width > totalSpace)
{
y += font.GetHeight();
tempX = x;
measureWord.Width = tempWordWidth;
}
G.DrawString(word + " ", font, brush, tempX, y);
tempX += tempWordWidth;
}
y += font.GetHeight();
}
示例6: ctlMCXY
//int mCircsize;
public ctlMCXY()
{
InitializeComponent();
mArches = new Image[4];
mArchesSel = new Image[4];
mOffsets = new Rectangle[4];
mArchTxtPos = new PointF[4];
mLevelVals = new float[] { 0.1f, 1, 10, 100 };
DoubleBuffered = true;
mSelAxis = 0;
mSelLevel = 0;
mCircWidth = 256;
Height = mCircWidth;
Width = mCircWidth;
mInRad = 35;
mButtRad = mCircWidth / 2;
mArchWidth = 20;
mCenter = mCircWidth / 2;
mButMin = mCenter - 60;
mButMax = mCenter - 10;
mButHomePos = 25;
mArrowPos = (int)(mCenter + mInRad) / 2;
Font = new Font("Arial", (float)(mArchWidth * 0.75), System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
UpdateOffsets(mCircWidth);
FrameColor = Color.RoyalBlue;
mUnit = "mm";
//UpdateBitmaps();
}
示例7: settings4_4_language_DrawItem
private void settings4_4_language_DrawItem(object sender, DrawItemEventArgs e)
{
Font objFonts = new Font(this.Font.Name, 14, FontStyle.Bold);
e.DrawBackground();
e.Graphics.DrawString(settings4_4_language.Items[e.Index].ToString(), objFonts, new SolidBrush(e.ForeColor), new Point(e.Bounds.Left, e.Bounds.Top));
}
示例8: SetReactions
protected void SetReactions(HXReaction curReaction, HXReaction newReaction)
{
ChangeGeneric(true);
Font BoldFont = new Font(txtCurReactants.Font, FontStyle.Bold);
txtCurGeneric.Text = curReaction.ToString();
txtNewGeneric.Text = newReaction.ToString();
Match curMatch = HXReaction.s_HXRegex.Match(txtCurGeneric.Text);
Match newMatch = HXReaction.s_HXRegex.Match(txtNewGeneric.Text);
string[] groups = new string[] { "Type", "Value", "Value2" };
foreach (string s in groups)
{
Group curGroup = curMatch.Groups[s];
Group newGroup = newMatch.Groups[s];
if (curGroup.Value != newGroup.Value)
{
if (curGroup.Success)
{
txtCurGeneric.Select(curGroup.Index, curGroup.Length);
HighlightText(txtCurGeneric);
}
if (newGroup.Success)
{
txtNewGeneric.Select(newGroup.Index, newGroup.Length);
HighlightText(txtNewGeneric);
}
}
}
}
示例9: QFont
public QFont(string fileName, float size, FontStyle style, QFontBuilderConfiguration config)
{
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile(fileName);
var fontFamily = pfc.Families[0];
if (!fontFamily.IsStyleAvailable(style))
throw new ArgumentException("Font file: " + fileName + " does not support style: " + style );
if (config == null)
config = new QFontBuilderConfiguration();
TransformViewport? transToVp = null;
float fontScale = 1f;
if (config.TransformToCurrentOrthogProjection)
transToVp = OrthogonalTransform(out fontScale);
using(var font = new Font(fontFamily, size * fontScale * config.SuperSampleLevels, style)){
fontData = BuildFont(font, config, null);
}
if (config.ShadowConfig != null)
Options.DropShadowActive = true;
if (transToVp != null)
Options.TransformToViewport = transToVp;
if(config.UseVertexBuffer)
InitVBOs();
}
示例10: LoadSystemFonts
/// <summary>
/// Load system fonts and create previews of them
/// </summary>
/// <returns>Total number of fonts loaded</returns>
public int LoadSystemFonts()
{
FontCollection fc = new InstalledFontCollection();
int fontCount = 0;
foreach (FontFamily f in fc.Families)
{
fontCount++;
try
{
FontStyle fs = FontStyle.Strikeout;
foreach (FontStyle fos in Enum.GetValues(typeof(FontStyle)))
{
if (fs == FontStyle.Strikeout && fos != FontStyle.Strikeout)
{
if (f.IsStyleAvailable(fos))
{
fs = fos;
}
}
}
Font fo = new Font(f, 38f, fs);
FamilyViewer fv = new FamilyViewer();
fv.PreviewFont = fo;
this.AddItem(fv);
}
catch (Exception ex)
{
System.Console.WriteLine("Problem displaying " + f.Name);
}
}
return fontCount;
}
示例11: OnPaint
protected override void OnPaint(PaintEventArgs pea)
{
base.OnPaint(pea);
Graphics grfx = pea.Graphics;
LinearGradientBrush lgbrush = null;
Font font = new Font(this.Font.FontFamily, this.Font.Size, this.Font.Style);
SolidBrush brush = new SolidBrush(this.ForeColor);
int cw = (this.Width - 20)/7;
int ch = this.Height - 20;
for(int i = 0 ; i < 7; i++)
{
Rectangle temp = new Rectangle(10+(i*cw), 10, cw, ch );
if(i < 6)
lgbrush = new LinearGradientBrush(temp, colors[i], colors[i+1], LinearGradientMode.Horizontal);
else
lgbrush = new LinearGradientBrush(temp, colors[i], colors[0], LinearGradientMode.Horizontal);
lgbrush.WrapMode = WrapMode.Tile;
grfx.FillRectangle(lgbrush, 10+(i*cw), 10, cw, ch );
}
grfx.DrawString(this.Text, font, brush, this.Width/3, this.Height/2);
}
示例12: UpdateMeasures
/// <summary>
/// Updates the width of the word as it would be
/// when drawn with the specified font in the specified graphics.
/// </summary>
public virtual void UpdateMeasures(Graphics graphics, Font font)
{
string word = _value;
int rangePos = 0;
int rangeLen = word.Length;
if (IsWhitespace)
{
// Enclose the word in printable characters for
// Graphics.MeasureText to work correctly.
// Furthermore tabs are not measured, so replace
// tabs with, say, 4 spaces
word = "W" + word + "W";
word = word.Replace("\t", " ");
rangePos = 1;
rangeLen = word.Length - 2;
}
_sformat.SetMeasurableCharacterRanges(new CharacterRange[]
{
new CharacterRange(rangePos, rangeLen)
});
Region[] r = graphics.MeasureCharacterRanges(
word, font, _srect, _sformat);
RectangleF bounds = r[0].GetBounds(graphics);
r[0].Dispose();
_width = bounds.Width;
}
示例13: FileSubMenu_DropDownOpened
private void FileSubMenu_DropDownOpened(object sender, EventArgs e)
{
SaveStateSubMenu.Enabled =
LoadStateSubMenu.Enabled =
SaveSlotSubMenu.Enabled =
Global.Emulator.HasSavestates();
OpenRomMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Open ROM"].Bindings;
CloseRomMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Close ROM"].Bindings;
MovieSubMenu.Enabled =
CloseRomMenuItem.Enabled =
!Global.Emulator.IsNull();
var hasSaveRam = Global.Emulator.HasSaveRam();
bool needBold = hasSaveRam && Global.Emulator.AsSaveRam().SaveRamModified;
SaveRAMSubMenu.Enabled = hasSaveRam;
if (SaveRAMSubMenu.Font.Bold != needBold)
{
var font = new System.Drawing.Font(SaveRAMSubMenu.Font, needBold ? FontStyle.Bold : FontStyle.Regular);
SaveRAMSubMenu.Font.Dispose();
SaveRAMSubMenu.Font = font;
}
}
示例14: FontCollection
private void FontCollection()
{
// Create the byte array and get its length
byte[] fontArray = Resources.gill_sans_ultra_bold_condensed;
int dataLength = Resources.gill_sans_ultra_bold_condensed.Length;
// ASSIGN MEMORY AND COPY BYTE[] ON THAT MEMORY ADDRESS
IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
Marshal.Copy(fontArray, 0, ptrData, dataLength);
uint cFonts = 0;
AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);
PrivateFontCollection pfc = new PrivateFontCollection();
//PASS THE FONT TO THE PRIVATEFONTCOLLECTION OBJECT
pfc.AddMemoryFont(ptrData, dataLength);
//FREE THE "UNSAFE" MEMORY
Marshal.FreeCoTaskMem(ptrData);
ff = pfc.Families[0];
font = new Font(ff, 15f, FontStyle.Bold);
fontButtonRegular = new Font(ff, 25f, FontStyle.Bold);
fontButtonSelected = new Font(ff, 30f, FontStyle.Bold);
fontRankings = new Font(ff, 25f, FontStyle.Bold);
MyButton._normalFont = fontButtonRegular;
MyButton._hoverFont = fontButtonSelected;
}
示例15: Main
public static void Main( string[] args ) {
Font f = new Font( "Tahoma", 70 );
Point drawPos;
string saveDir = AppDomain.CurrentDomain.BaseDirectory + @"\Minimap\";
System.IO.Directory.CreateDirectory( saveDir );
for( int i = 0; i < 200; i++ ) {
Console.WriteLine( "build Image " + i + ".." );
using( Bitmap bmp = new Bitmap( 512, 512 ) ) {
using( Graphics g = Graphics.FromImage( bmp ) ) {
SizeF stringSize = g.MeasureString( i.ToString(), f );
drawPos = new Point( 256 - (int)stringSize.Width / 2, 256 - (int)stringSize.Height / 2 );
g.DrawString( i.ToString(), f, Brushes.White, drawPos );
}
DevIL.DevIL.SaveBitmap( saveDir + i + ".tga", bmp );
}
}
Console.WriteLine( "\nfinished" );
Console.ReadKey();
}