Form1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:2k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. namespace DrawText
  8. {
  9. /// <summary>
  10. /// Summary description for Form1.
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. /// <summary>
  15. /// Required designer variable.
  16. /// </summary>
  17. private System.ComponentModel.Container components = null;
  18. public Form1()
  19. {
  20. //
  21. // Required for Windows Form Designer support
  22. //
  23. InitializeComponent();
  24. this.BackColor = Color.White;
  25. this.Text = "DisplayText";
  26. //
  27. // TODO: Add any constructor code after InitializeComponent call
  28. //
  29. }
  30. private Brush blackBrush = Brushes.Black;
  31. private Brush blueBrush = Brushes.Blue;
  32. private Font haettenschweilerFont = new Font("Haettenschweiler", 12);
  33. private Font boldTimesFont = new Font("Times New Roman", 10, FontStyle.Bold);
  34. private Font italicCourierFont = new Font("Courier", 11, FontStyle.Italic | 
  35. FontStyle.Underline);
  36. protected override void OnPaint(PaintEventArgs e)
  37. {
  38. base.OnPaint(e);
  39. Graphics dc = e.Graphics;
  40. dc.DrawString("This is a groovy string", haettenschweilerFont, blackBrush, 
  41. 10, 10);
  42. dc.DrawString("This is a groovy string " +
  43. "with some very long text that will never fit in the box", 
  44. boldTimesFont, blueBrush, 
  45. new Rectangle(new Point(10, 40), new Size(100, 40)));
  46. dc.DrawString("This is a groovy string", italicCourierFont, blackBrush, 
  47. new Point(10, 100));
  48. }
  49. /// <summary>
  50. /// Clean up any resources being used.
  51. /// </summary>
  52. protected override void Dispose( bool disposing )
  53. {
  54. if( disposing )
  55. {
  56. if (components != null) 
  57. {
  58. components.Dispose();
  59. }
  60. }
  61. base.Dispose( disposing );
  62. }
  63. #region Windows Form Designer generated code
  64. /// <summary>
  65. /// Required method for Designer support - do not modify
  66. /// the contents of this method with the code editor.
  67. /// </summary>
  68. private void InitializeComponent()
  69. {
  70. this.components = new System.ComponentModel.Container();
  71. this.Size = new System.Drawing.Size(300,300);
  72. this.Text = "Form1";
  73. }
  74. #endregion
  75. /// <summary>
  76. /// The main entry point for the application.
  77. /// </summary>
  78. [STAThread]
  79. static void Main() 
  80. {
  81. Application.Run(new Form1());
  82. }
  83. }
  84. }