前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
Font m_font;
m_font = new Font("MS 明朝", 12);
|
bool m_flag; // Text 更新フラグ
Font m_font; // フォントの定義
string XML_File = @"C:\tmp\edit.xml";
public class XmlClass
{ public string name; // Font Name
public float point; // Font Size
}
|
private void Form_Load(object sender, EventArgs e)
{
Width = 1000;
Height = 480;
if (File.Exists(XML_File)) //ファイルの有無をチェック
{ System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(typeof(XmlClass));
System.IO.FileStream fs =
new System.IO.FileStream(XML_File, System.IO.FileMode.Open);
XmlClass obj = (XmlClass)serializer.Deserialize(fs);
fs.Close();
int point = (int)obj.point;
m_font = new Font(obj.name, point);
}
else m_font = new Font("MS 明朝", 12);
richTextBox1.Font = m_font;
richTextBox1.LanguageOption = RichTextBoxLanguageOptions.UIFonts;
}
|
private void Form_Closing(object sender, FormClosingEventArgs e)
{
if (Cancel_Check())
{
e.Cancel = true;
return;
}
XmlClass obj = new XmlClass();
obj.name = m_font.Name;
obj.point = m_font.SizeInPoints;
System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(typeof(XmlClass));
System.IO.FileStream fs =
new System.IO.FileStream(XML_File, System.IO.FileMode.Create);
serializer.Serialize(fs, obj);
}
|
エラー 1 型または名前空間名 'Xml' は名前空間 'System' に存在しません。 アセンブリ参照が不足しています。 |
using System.Xml.Serialization; // System.Xml.dll を追加 |
private void SetFont(object sender, EventArgs e)
{
FontDialog fontDialog1 = new FontDialog();
fontDialog1.Font = m_font;
fontDialog1.MaxSize = 32;
fontDialog1.MinSize = 9;
fontDialog1.FontMustExist = true;
fontDialog1.FixedPitchOnly = true;
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
m_font = fontDialog1.Font;
this.richTextBox1.Font = m_font;
}
fontDialog1.Dispose();
}
|
![]()
[Next Chapter ↓] 検索機能
[Previous Chapter ↑] Contex Menu