Xamarin.Forms使用 Fontello 字體的字形很
匯出字體:
[assembly: ExportFont("smiley.ttf", Alias = "smiley")]
使用屬性的xaml字形Text:
<StackLayout BackgroundColor="#eeeeee">
<!--Uses glyph #E800 from smiley.ttf-->
<Button BorderColor="Aqua"
BackgroundColor="Yellow"
BorderWidth="5"
CornerRadius="10"
FontSize="150"
FontFamily="smiley"
Text=""
TextColor="Black"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
HeightRequest="200"
WidthRequest="200" />
</StackLayout>
并且很快:

我想在Winforms. 這是我嘗試過的:
public MainForm()
{
InitializeComponent();
// For the sake of simplicity, the TTF is copied to output directory...
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Fonts", "smiley.ttf");
// ... and loaded here.
privateFontCollection.AddFontFile(path);
var fontFamily = privateFontCollection.Families[0];
Debug.Assert(fontFamily.Name == "smiley", "Expecting 'smiley' is the font family name");
button1.Font = new Font(fontFamily, 12F);
button1.UseCompatibleTextRendering = true;
// Shows 'A'
// button1.Text = "A";
// Shows nothing.
button1.Text = "\u0E00";
}
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
這樣的事情甚至可能嗎?我嘗試了各種設定button1.UseCompatibleTextRendering = true但Application.SetCompatibleTextRenderingDefault(true)沒有成功。
uj5u.com熱心網友回復:
問題的答案:Fontello 字形能否以與 Xamarin Forms 按鈕類似的方式用于 Winforms 按鈕?是的。
感謝 Jimi 的評論指出了我的錯字,并提到了我也不知道的處置的必要性。

這是作業代碼:
public partial class MainForm : Form
{
// https://stackoverflow.com/a/36509042/5438626
// https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-create-a-private-font-collection?view=netframeworkdesktop-4.8
public MainForm()
{
InitializeComponent();
// For the sake of simplicity, the TTF is copied to output directory...
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Fonts", "smiley.ttf");
// ... and loaded here.
privateFontCollection.AddFontFile(path);
var fontFamily = privateFontCollection.Families[0];
Debug.Assert(fontFamily.Name == "smiley", "Expecting 'smiley' is the font family name");
button1.Font = new Font(fontFamily, 12F);
button1.UseCompatibleTextRendering = true;
button1.Text = "\uE800";
button1.BackColor = Color.Yellow;
}
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
privateFontCollection.Dispose();
}
base.Dispose(disposing);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489377.html
標籤:表格 xamarin.forms 丰泰罗
上一篇:無法將“ModelDetailView”型別的物件轉換為“DevExpress.ExpressApp.ViewVariantsModule.IModelViewVariants”
