2 回答

TA貢獻1942條經驗 獲得超3個贊
添加我在評論中所說的內容以及 Piotr 在他的回答中開始的內容。我建議將Fonts類更改為靜態(因為它的所有方法都不依賴于狀態)。
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使用您在示例中提供的語法來訪問這些方法。

TA貢獻1804條經驗 獲得超7個贊
使方法TitleFont靜態
public static Font TitleFont()
{
return new Font("Arial", 12, FontStyle.Bold);
}
然后做:
using Project.Utility;
private void MyMethod(){
title.Font = Fonts.TitleFont();
}
- 2 回答
- 0 關注
- 218 瀏覽
添加回答
舉報