Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 3k
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.   
  9. namespace ch2_2
  10. {
  11. /// <summary>
  12. /// Form1 的摘要说明。
  13. /// </summary>
  14. public class Form1 : System.Windows.Forms.Form
  15. {
  16. /// <summary>
  17. /// 必需的设计器变量。
  18. /// </summary>
  19. private System.ComponentModel.Container components = null;
  20. public Form1()
  21. {
  22. //
  23. // Windows 窗体设计器支持所必需的
  24. //
  25. InitializeComponent();
  26. //
  27. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  28. //
  29. }
  30. /// <summary>
  31. /// 清理所有正在使用的资源。
  32. /// </summary>
  33. protected override void Dispose( bool disposing )
  34. {
  35. if( disposing )
  36. {
  37. if (components != null) 
  38. {
  39. components.Dispose();
  40. }
  41. }
  42. base.Dispose( disposing );
  43. }
  44. #region Windows Form Designer generated code
  45. /// <summary>
  46. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  47. /// 此方法的内容。
  48. /// </summary>
  49. private void InitializeComponent()
  50. {
  51. // 
  52. // Form1
  53. // 
  54. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  55. this.ClientSize = new System.Drawing.Size(492, 323);
  56. this.Name = "Form1";
  57. this.Text = "图形色彩从中心到边缘的变化";
  58. }
  59. #endregion
  60. /// <summary>
  61. /// 应用程序的主入口点。
  62. /// </summary>
  63. protected override void OnPaint(PaintEventArgs e) 
  64. {
  65. //获得Graphics对象
  66. Graphics g = e.Graphics;
  67.             //图像呈现质量为消除锯齿
  68. g.SmoothingMode = SmoothingMode.AntiAlias;
  69.             //使用SolidBrush将窗体涂为白色
  70.     g.FillRectangle(new SolidBrush(Color.White), this.ClientRectangle);
  71. //创建一个包含单个椭圆路径的path对象
  72. GraphicsPath path = new GraphicsPath();
  73.     path.AddEllipse(250,100,200,100);
  74. //path.AddEllipse(100, 100, 280, 140);
  75. // 使用这个Path对象创建一个渐变路径画笔.
  76. PathGradientBrush pBrush = new PathGradientBrush(path);
  77. // 将path对象的中心颜色设为蓝色
  78. pBrush.CenterColor = Color.Blue;
  79. // 将环绕在path对象边界上的颜色设为Aqua
  80. Color[] colors = {Color.Aqua};
  81. pBrush.SurroundColors = colors;
  82. //绘制椭圆
  83.             g.FillEllipse(pBrush, 250,100,200,100);
  84.  
  85.     GraphicsPath path1 = new GraphicsPath();
  86.    //设置五角星的每点的坐标数组
  87. Point[] points = {
  88.  new Point(125, 75),
  89.  new Point(150, 125),
  90.  new Point(200, 125),
  91.  new Point(162, 150),
  92.  new Point(200, 225),
  93.  new Point(125, 175),
  94.  new Point(50, 225),
  95.  new Point(87, 150),
  96.  new Point(50, 125),
  97.  new Point(100, 125)};
  98. path1.AddLines(points);
  99. PathGradientBrush pBrush1 = new PathGradientBrush(path1);
  100. //构造ColorBlend对象,用于多色渐变
  101. ColorBlend colorBlend = new ColorBlend();
  102. //定义三种颜色的多色渐变
  103. colorBlend.Colors = new Color[]
  104. {
  105. Color.Blue, Color.Aqua, Color.Green
  106. };
  107. //定义每一种颜色的位置
  108. colorBlend.Positions = new float[]
  109. {
  110. 0.0f, 0.4f, 1.0f
  111. };
  112. //把colorBlend对象赋给刷子的InterpolationColor属性
  113. pBrush1.InterpolationColors = colorBlend;
  114. //绘制五角星
  115.             g.FillRectangle(pBrush1, new Rectangle(0, 0, 200, 225));
  116.   
  117. }
  118. [STAThread]
  119. static void Main() 
  120. {
  121. Application.Run(new Form1());
  122. }
  123. }
  124. }