프로그래밍/C#
C# Font XML로 저장 및 읽기
프로그래머 ^.^
2014. 11. 4. 19:01
C# Font XML로 저장 및 읽기
Font Class를 XML로 저장할때 일반적인 경우 XMLSrializing 을 사용해서 구현한다.
싸이트 뒤지면 http://www.codeproject.com/Questions/423759/how-to-serialize-font 에 보시라
어떤가 좀 복잡하다.
내가 사용하는 방법
FontConverter 클래스 사용 (MS 도움말에 나오는 예제)
1 private void ShowFontStringConversion(PaintEventArgs e) 2 { 3 // Create the FontConverter. 4 System.ComponentModel.TypeConverter converter = 5 System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font)); 6 7 Font font1 = (Font) converter.ConvertFromString("Arial, 12pt"); 8 9 string fontName1 = converter.ConvertToInvariantString(font1); 10 string fontName2 = converter.ConvertToString(font1); 11 12 e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10); 13 e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30); 14 }
4번줄 - Font Type의 Converter를 생성한다.
7번줄 - Font를 string으로 생성한다.
Visual Studio C#에 개체 속성창을 보면 Font를 설정하고 표현되는 내용 형식으로
구성되어 있다.
10번줄 - Font 개체를 string으로 변환한다. 그러면 7번줄에서 string으로 입력한 Font 내용과 같은 string으로 만들어 진다.