for Push.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using KssSmaPlaLib.Ini;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace KssSmaPlaLib.Forms.ContextMenuFunction
|
||||
{
|
||||
public static class FontUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// フォント選択
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultFont"></param>
|
||||
/// <param name="resultFont"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SelectFont(Form form, string section, string key, Font defaultFont, out Font resultFont)
|
||||
{
|
||||
// デフォルト値
|
||||
resultFont = new Font(defaultFont, defaultFont.Style);
|
||||
|
||||
using (var dlg = new FontDialog())
|
||||
{
|
||||
var defaultFontCsv =
|
||||
defaultFont.Name + "," +
|
||||
defaultFont.Size.ToString() + "," +
|
||||
defaultFont.Bold.ToString();
|
||||
var iniFontCsv = IniHelper.ReadValue(null, section, key, defaultFontCsv);
|
||||
var fontItems = iniFontCsv.Split(',');
|
||||
if (fontItems.Length != 3) fontItems = defaultFontCsv.Split(',');
|
||||
if (float.TryParse(fontItems[1], out var size) == false) size = defaultFont.Size;
|
||||
if (bool.TryParse(fontItems[2], out var bold) == false) bold = defaultFont.Bold;
|
||||
|
||||
dlg.Font = new Font(fontItems[0], size, bold ? FontStyle.Bold : FontStyle.Regular);
|
||||
dlg.AllowVerticalFonts = false;
|
||||
// 文字飾り(取り消し線と下線)を表示させない
|
||||
dlg.ShowEffects = false;
|
||||
var result = dlg.ShowDialog(form);
|
||||
if (result == DialogResult.Cancel) return false;
|
||||
|
||||
// INI保存
|
||||
var fontCsv =
|
||||
dlg.Font.Name + "," +
|
||||
dlg.Font.Size.ToString() + "," +
|
||||
dlg.Font.Bold.ToString();
|
||||
IniHelper.WriteValue(null, section, key, fontCsv);
|
||||
|
||||
// 出力
|
||||
resultFont = new Font(dlg.Font, dlg.Font.Style);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static Font GetFont(string section, string key, Font defaultFont)
|
||||
{
|
||||
var defaultFontCsv =
|
||||
defaultFont.Name + "," +
|
||||
defaultFont.Size.ToString() + "," +
|
||||
defaultFont.Bold.ToString();
|
||||
|
||||
var iniFontCsv = IniHelper.ReadValue(null, section, key, defaultFontCsv);
|
||||
var fontItems = iniFontCsv.Split(',');
|
||||
if (fontItems.Length != 3) fontItems = defaultFontCsv.Split(',');
|
||||
if (float.TryParse(fontItems[1], out var size) == false) size = defaultFont.Size;
|
||||
if (bool.TryParse(fontItems[2], out var bold) == false) bold = defaultFont.Bold;
|
||||
return new Font(fontItems[0], size, bold ? FontStyle.Bold : FontStyle.Regular);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user