FontDialogSample.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // Test application for the FontDialog class implementation
  3. //
  4. // Author:
  5. // Jordi Mas i Hernàndez, [email protected]
  6. //
  7. using System;
  8. using System.Collections;
  9. using System.Windows.Forms;
  10. using System.Drawing;
  11. //
  12. namespace FontDialogTest
  13. {
  14. public class myButton : System.Windows.Forms.Button
  15. {
  16. public FontDialog fontDialog = null;
  17. public TestForm testForm = null;
  18. public FontDialog fontdlg { get { return fontDialog; } }
  19. public myButton(TestForm testFrm) : base()
  20. {
  21. fontDialog = new FontDialog();
  22. testForm = testFrm;
  23. }
  24. /* User clicks the button*/
  25. protected override void OnClick(EventArgs e)
  26. {
  27. // Show default values
  28. Console.WriteLine("Default values---");
  29. Console.WriteLine("AllowScriptChange " + fontDialog.AllowScriptChange);
  30. Console.WriteLine("Color " + fontDialog.Color);
  31. Console.WriteLine("FixedPitchOnly " + fontDialog.FixedPitchOnly);
  32. Console.WriteLine("Font " + fontDialog.Font);
  33. Console.WriteLine("FontMustExist " + fontDialog.FontMustExist);
  34. Console.WriteLine("MaxSize " + fontDialog.MaxSize);
  35. Console.WriteLine("MinSize " + fontDialog.MinSize);
  36. Console.WriteLine("ScriptsOnly " + fontDialog.ScriptsOnly);
  37. Console.WriteLine("ShowApply " + fontDialog.ShowApply);
  38. Console.WriteLine("ShowColor " + fontDialog.ShowColor);
  39. Console.WriteLine("ShowEffects " + fontDialog.ShowEffects);
  40. Console.WriteLine("ShowHelp " + fontDialog.ShowHelp);
  41. testForm.Update();
  42. fontDialog.ShowColor = true;
  43. fontDialog.Color = Color.Red;
  44. fontDialog.MinSize = 10;
  45. fontDialog.MaxSize = 12;
  46. if(fontDialog.ShowDialog(this) != DialogResult.Cancel )
  47. {
  48. Console.WriteLine("Seleted Font " + fontDialog.Font.FontFamily.Name);
  49. Console.WriteLine("Seleted Size " + fontDialog.Font.Size);
  50. Console.WriteLine("Seleted Color " + fontDialog.Color);
  51. testForm.Update();
  52. }
  53. else
  54. {
  55. fontDialog.Reset();
  56. testForm.Update();
  57. }
  58. }
  59. }
  60. public class TestForm : System.Windows.Forms.Form
  61. {
  62. TextBox fontName = null;
  63. TextBox fontSize = null;
  64. TextBox fontColor = null;
  65. myButton button = null;
  66. public static void Main(string[] args)
  67. {
  68. Application.Run(new TestForm());
  69. }
  70. public TestForm()
  71. {
  72. InitializeComponent();
  73. }
  74. private void InitializeComponent()
  75. {
  76. Text = "Test application for the FontDialog class implementation";
  77. FontDialog fontDialog = new FontDialog();
  78. ClientSize = new System.Drawing.Size(300, 300);
  79. button = new myButton(this);
  80. button.Location = new System.Drawing.Point(5, 10);
  81. button.Name = "button20";
  82. button.Size = new System.Drawing.Size(100, 30);
  83. button.Text = "Press me baby";
  84. button.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
  85. Controls.Add(button);
  86. fontName = new TextBox();
  87. fontName.Location = new System.Drawing.Point(5, 60);
  88. fontName.Name = "FontName";
  89. fontName.Size = new System.Drawing.Size(200, 30);
  90. fontName.ReadOnly = true;
  91. Controls.Add(fontName);
  92. fontSize = new TextBox();
  93. fontSize.Location = new System.Drawing.Point(5, 100);
  94. fontSize.Name = "FontSize";
  95. fontSize.Size = new System.Drawing.Size(200, 30);
  96. fontSize.ReadOnly = true;
  97. Controls.Add(fontSize);
  98. fontColor = new TextBox();
  99. fontColor.Location = new System.Drawing.Point(5, 140);
  100. fontColor.Name = "FontSize";
  101. fontColor.Size = new System.Drawing.Size(200, 30);
  102. fontColor.ReadOnly = true;
  103. Controls.Add(fontColor);
  104. return;
  105. }
  106. public new void Update()
  107. {
  108. //fontName.Text = "Font: " + button.fontDialog.MaxSize + " "+ button.fontDialog.MinSize;
  109. fontName.Text = "Font: " + button.fontDialog.Font.FontFamily.Name;
  110. fontSize.Text = "Size: " + button.fontDialog.Font.Size;
  111. fontColor.Text = "Color: " + button.fontDialog.Color;
  112. }
  113. }
  114. }