Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 4k
Category:

ADO-ODBC

Development Platform:

C#

  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. using System.Drawing.Drawing2D; 
  8. namespace ch2_5
  9. {
  10. /// <summary>
  11. /// Form1 的摘要说明。
  12. /// </summary>
  13. public class Form1 : System.Windows.Forms.Form
  14. {
  15. /// <summary>
  16. /// 必需的设计器变量。
  17. /// </summary>
  18. private System.ComponentModel.Container components = null;
  19. public Form1()
  20. {
  21. //
  22. // Windows 窗体设计器支持所必需的
  23. //
  24. InitializeComponent();
  25. //
  26. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  27. //
  28. }
  29. /// <summary>
  30. /// 清理所有正在使用的资源。
  31. /// </summary>
  32. protected override void Dispose( bool disposing )
  33. {
  34. if( disposing )
  35. {
  36. if (components != null) 
  37. {
  38. components.Dispose();
  39. }
  40. }
  41. base.Dispose( disposing );
  42. }
  43. #region Windows Form Designer generated code
  44. /// <summary>
  45. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  46. /// 此方法的内容。
  47. /// </summary>
  48. private void InitializeComponent()
  49. {
  50. // 
  51. // Form1
  52. // 
  53. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  54. this.ClientSize = new System.Drawing.Size(520, 357);
  55. this.Name = "Form1";
  56. this.Text = "演示画笔和曲线";
  57. }
  58. #endregion
  59. protected override void OnPaint(PaintEventArgs e) 
  60. {
  61. Graphics g = e.Graphics;
  62.             //图像效果为消除锯齿
  63. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  64. //设置背景颜色
  65.             g.FillRectangle(new SolidBrush(Color.Aqua), ClientRectangle);
  66.             
  67. Pen pen= new Pen(Color.Blue,2f);
  68. //做成点划线笔
  69. pen.DashStyle=DashStyle.DashDot;
  70. g.DrawLine(pen,20,15,480,15);
  71. //创建一支粗画笔 
  72. Pen pen1 = new Pen(Color.Blue, 20);
  73. //将其做成点线笔
  74. pen1.DashStyle = DashStyle.Dot;
  75. g.DrawLine(pen1,20,45,480,45);
  76.             
  77. Pen pen2 = new Pen(Color.Blue, 20);
  78. //将其做成虚线笔
  79. pen2.DashStyle = DashStyle.Dash;
  80.             //使开始端为圆角
  81. pen2.StartCap = LineCap.Round;
  82.             //使末端成为箭头
  83. pen2.EndCap = LineCap.ArrowAnchor;
  84. g.DrawLine(pen2,20,90,480,90);
  85. Pen pen3= new Pen(Color.Blue, 2);
  86.             Point[] points= new Point[] {
  87.  new Point(20, 135),
  88.  new Point(40, 145),
  89.  new Point(30, 180),
  90.  new Point(160, 140),
  91.          new Point(300,120),
  92.  new Point(470, 140),
  93. };
  94. //绘制一条曲线,定义弯曲强度
  95. g.DrawCurve(pen3,points,1.2f);
  96. //标注定义点
  97. foreach (Point p in points)
  98. {
  99. g.DrawEllipse(pen3,p.X-5,p.Y-5,10,10);
  100. }
  101. Pen pen4= new Pen(Color.Blue, 2);
  102. Point[] points1=new Point[] {
  103.   new Point(40, 220),
  104.   new Point(70, 200),
  105.   new Point(120, 190),
  106.   new Point(160, 250),
  107.   new Point(300,220),
  108.   new Point(470, 190),
  109. };
  110. //绘制封闭曲线
  111. g.DrawClosedCurve(pen4, points1);
  112. //标注定义点
  113. foreach (Point p in points1)
  114. {
  115. g.DrawEllipse(pen4,p.X-5,p.Y-5,10,10);
  116. }
  117.             
  118.        
  119. Pen pen5= new Pen(Color.Blue, 1);
  120. g.DrawString("贝赛尔曲线",this.Font,new SolidBrush(Color.Blue),20,260);
  121. Point[] points2=new Point[]{
  122.    new Point(100,260),
  123.    new Point(150,340),
  124.                    new Point(320,270),
  125.                    new Point(480,260)
  126.    };
  127. //绘制贝赛尔曲线
  128.             g.DrawBezier(pen5,points2[0],points2[1],points2[2],points2[3]);
  129. //显示贝赛尔曲线的控制点
  130. foreach (Point p in points2)
  131. {
  132. g.DrawEllipse(pen5,p.X-5,p.Y-5,10,10);
  133. }
  134. }
  135. /// <summary>
  136. /// 应用程序的主入口点。
  137. /// </summary>
  138. [STAThread]
  139. static void Main() 
  140. {
  141. Application.Run(new Form1());
  142. }
  143. }
  144. }