Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharpNotesForProfessionals.pdf
Скачиваний:
57
Добавлен:
20.05.2023
Размер:
6.12 Mб
Скачать

Chapter 160: Including Font Resources

Parameter Details

fontbytes byte array from the binary .ttf

Section 160.1: Instantiate 'Fontfamily' from Resources

public FontFamily Maneteke = GetResourceFontFamily(Properties.Resources.manteka);

Section 160.2: Integration method

public static FontFamily GetResourceFontFamily(byte[] fontbytes)

{

PrivateFontCollection pfc = new PrivateFontCollection();

IntPtr fontMemPointer = Marshal.AllocCoTaskMem(fontbytes.Length); Marshal.Copy(fontbytes, 0, fontMemPointer, fontbytes.Length); pfc.AddMemoryFont(fontMemPointer, fontbytes.Length); Marshal.FreeCoTaskMem(fontMemPointer);

return pfc.Families[0];

}

Section 160.3: Usage with a 'Button'

public static class Res

{

///<summary>

///URL: https://www.behance.net/gallery/2846011/Manteka

///</summary>

public static FontFamily Maneteke = GetResourceFontFamily(Properties.Resources.manteka);

public static FontFamily GetResourceFontFamily(byte[] fontbytes)

{

PrivateFontCollection pfc = new PrivateFontCollection();

IntPtr fontMemPointer = Marshal.AllocCoTaskMem(fontbytes.Length); Marshal.Copy(fontbytes, 0, fontMemPointer, fontbytes.Length); pfc.AddMemoryFont(fontMemPointer, fontbytes.Length); Marshal.FreeCoTaskMem(fontMemPointer);

return pfc.Families[0];

}

}

GoalKicker.com – C# Notes for Professionals

759

public class FlatButton : Button

{

public FlatButton() : base()

{

Font = new Font(Res.Maneteke, Font.Size);

}

protected override void OnFontChanged(EventArgs e)

{

base.OnFontChanged(e);

this.Font = new Font(Res.Maneteke, this.Font.Size);

}

}

GoalKicker.com – C# Notes for Professionals

760