- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
Form1.cs
资源名称:VC#.NET范例.rar [点击查看]
上传用户:chinafred
上传日期:2007-08-14
资源大小:10127k
文件大小:5k
源码类别:
数据库编程
开发平台:
C#
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Drawing.Drawing2D;
- namespace ch2_1
- {
- /// <summary>
- /// Form1 的摘要说明。
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- private System.Windows.Forms.ContextMenu contextMenu1;
- private System.Windows.Forms.MenuItem menuItem1;
- private System.Windows.Forms.MenuItem menuItem2;
- private System.Windows.Forms.MenuItem menuItem3;
- private System.Windows.Forms.MenuItem menuItem4;
- private System.Windows.Forms.MenuItem menuItem5;
- private LinearGradientMode lgMode=LinearGradientMode.Horizontal;
- public Form1()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
- this.contextMenu1 = new System.Windows.Forms.ContextMenu();
- this.menuItem1 = new System.Windows.Forms.MenuItem();
- this.menuItem2 = new System.Windows.Forms.MenuItem();
- this.menuItem3 = new System.Windows.Forms.MenuItem();
- this.menuItem4 = new System.Windows.Forms.MenuItem();
- this.menuItem5 = new System.Windows.Forms.MenuItem();
- //
- // contextMenu1
- //
- this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuItem1});
- //
- // menuItem1
- //
- this.menuItem1.Index = 0;
- this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuItem2,
- this.menuItem3,
- this.menuItem4,
- this.menuItem5});
- this.menuItem1.Text = "颜色变化方向";
- //
- // menuItem2
- //
- this.menuItem2.Index = 0;
- this.menuItem2.Text = "从上到下";
- this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
- //
- // menuItem3
- //
- this.menuItem3.Index = 1;
- this.menuItem3.Text = "从左到右";
- this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
- //
- // menuItem4
- //
- this.menuItem4.Index = 2;
- this.menuItem4.Text = "有右上到左下";
- this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
- //
- // menuItem5
- //
- this.menuItem5.Index = 3;
- this.menuItem5.Text = "从左上到右下";
- this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
- this.ClientSize = new System.Drawing.Size(492, 273);
- this.ContextMenu = this.contextMenu1;
- this.Name = "Form1";
- this.Text = "色彩渐变的图形";
- }
- #endregion
- protected override void OnPaint(PaintEventArgs e)
- {
- //获取事件的Graphics对象
- Graphics g = e.Graphics;
- //现在创建需要绘制的长方形区域
- Rectangle r = new Rectangle(75, 50, 350, 170);
- //创建一个渐变刷
- LinearGradientBrush lb = new LinearGradientBrush(r, Color.White,Color.Blue, lgMode);
- //用渐变刷填充长方形区域
- g.FillRectangle(lb, r);
- }
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void menuItem2_Click(object sender, System.EventArgs e)
- {
- //指定从上到下的渐变
- this.lgMode=LinearGradientMode.Vertical;
- this.Refresh();
- }
- private void menuItem3_Click(object sender, System.EventArgs e)
- {
- //指定从左到右的渐变。
- this.lgMode=LinearGradientMode.Horizontal;
- this.Refresh();
- }
- private void menuItem4_Click(object sender, System.EventArgs e)
- {
- //指定从右上到左下的渐变。
- this.lgMode=LinearGradientMode.BackwardDiagonal;
- this.Refresh();
- }
- private void menuItem5_Click(object sender, System.EventArgs e)
- {
- //从左上到右下的渐变。
- this.lgMode=LinearGradientMode.ForwardDiagonal;
- this.Refresh();
- }
- }
- }