2 回答

TA貢獻(xiàn)1942條經(jīng)驗(yàn) 獲得超3個(gè)贊
添加我在評(píng)論中所說(shuō)的內(nèi)容以及 Piotr 在他的回答中開(kāi)始的內(nèi)容。我建議將Fonts類(lèi)更改為靜態(tài)(因?yàn)樗乃蟹椒ǘ疾灰蕾?lài)于狀態(tài))。
public static class Fonts
{
public static Font TitleFont()
{
var font = new Font("Arial", 12, FontStyle.Bold);
return font;
}
public static Font SubtitleFont()
{
var font = new Font("Arial", 8, FontStyle.Italic);
return font;
}
public static Font TotalMinutesFont()
{
var font = new Font("Arial", 8, FontStyle.Regular);
return font;
}
}
然后,您可以Fonts使用您在示例中提供的語(yǔ)法來(lái)訪問(wèn)這些方法。

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊
使方法TitleFont靜態(tài)
public static Font TitleFont()
{
return new Font("Arial", 12, FontStyle.Bold);
}
然后做:
using Project.Utility;
private void MyMethod(){
title.Font = Fonts.TitleFont();
}
- 2 回答
- 0 關(guān)注
- 208 瀏覽
添加回答
舉報(bào)