⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 图元变换
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		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()
		{
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.Button6 = new System.Windows.Forms.Button();
			this.Button5 = new System.Windows.Forms.Button();
			this.Button4 = new System.Windows.Forms.Button();
			this.Button3 = new System.Windows.Forms.Button();
			this.Button2 = new System.Windows.Forms.Button();
			this.Button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.BackColor = System.Drawing.Color.White;
			this.pictureBox1.Location = new System.Drawing.Point(8, 8);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(312, 280);
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			// 
			// Button6
			// 
			this.Button6.Location = new System.Drawing.Point(344, 256);
			this.Button6.Name = "Button6";
			this.Button6.Size = new System.Drawing.Size(64, 24);
			this.Button6.TabIndex = 12;
			this.Button6.Text = "取  消";
			this.Button6.Click += new System.EventHandler(this.Button6_Click_1);
			// 
			// Button5
			// 
			this.Button5.Location = new System.Drawing.Point(344, 208);
			this.Button5.Name = "Button5";
			this.Button5.Size = new System.Drawing.Size(64, 24);
			this.Button5.TabIndex = 11;
			this.Button5.Text = "缩  小";
			this.Button5.Click += new System.EventHandler(this.Button5_Click_1);
			// 
			// Button4
			// 
			this.Button4.Location = new System.Drawing.Point(344, 160);
			this.Button4.Name = "Button4";
			this.Button4.Size = new System.Drawing.Size(64, 24);
			this.Button4.TabIndex = 10;
			this.Button4.Text = "放  大";
			this.Button4.Click += new System.EventHandler(this.Button4_Click_1);
			// 
			// Button3
			// 
			this.Button3.Location = new System.Drawing.Point(344, 64);
			this.Button3.Name = "Button3";
			this.Button3.Size = new System.Drawing.Size(64, 24);
			this.Button3.TabIndex = 9;
			this.Button3.Text = "右 移";
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			// 
			// Button2
			// 
			this.Button2.Location = new System.Drawing.Point(344, 112);
			this.Button2.Name = "Button2";
			this.Button2.Size = new System.Drawing.Size(64, 24);
			this.Button2.TabIndex = 8;
			this.Button2.Text = "旋  转";
			this.Button2.Click += new System.EventHandler(this.Button2_Click_1);
			// 
			// Button1
			// 
			this.Button1.Location = new System.Drawing.Point(344, 16);
			this.Button1.Name = "Button1";
			this.Button1.Size = new System.Drawing.Size(64, 24);
			this.Button1.TabIndex = 7;
			this.Button1.Text = "左  移";
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(424, 302);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
			this.Button6,
			this.Button5,
			this.Button4,
			this.Button3,
			this.Button2,
			this.Button1,
			this.pictureBox1});
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private System.Windows.Forms.PictureBox pictureBox1;
		internal System.Windows.Forms.Button Button6;
		internal System.Windows.Forms.Button Button5;
		internal System.Windows.Forms.Button Button4;
		internal System.Windows.Forms.Button Button3;
		internal System.Windows.Forms.Button Button2;
		internal System.Windows.Forms.Button Button1;
		private Graphics g;


		private void Button1_Click(object sender,EventArgs e)
		{
			//左移
			g = pictureBox1.CreateGraphics();
			g.Clear(Color.White);
			g.TranslateTransform(-50, 0);
			Draw(g);
		}


		private void PictureBox1_Paint(object sender, EventArgs e)
	    {
			g = pictureBox1.CreateGraphics();
			Draw(g);
		}

		private void Draw(Graphics g)
	    {
			//绘图
			g.DrawLine(Pens.Black, 10, 10, 100, 100);
			g.DrawEllipse(Pens.Black, 50, 50, 200, 100);
			g.DrawArc(Pens.Black, 100, 10, 100, 100, 20, 160);
			g.FillRectangle(Brushes.Green, 50, 200, 150, 100);
		}

		private void Button3_Click(object sender, EventArgs e)
	    {
			//右移
			Graphics g= pictureBox1.CreateGraphics();
			g.Clear(Color.White);
			g.TranslateTransform(50, 0);
			Draw(g);
		}

		private void Button2_Click_1(object sender, System.EventArgs e)
		{
			//旋转
			g = pictureBox1.CreateGraphics();
			g.Clear(Color.White);
			g.RotateTransform(-30);
			Draw(g);
		}

		private void Button4_Click_1(object sender, System.EventArgs e)
		{
			//放大
			g = pictureBox1.CreateGraphics();
			g.Clear(Color.White);
			g.ScaleTransform(1.2f, 1.2f);
			Draw(g);
		}

		private void Button5_Click_1(object sender, System.EventArgs e)
		{
			//缩小
			g = pictureBox1.CreateGraphics();
			g.Clear(Color.White);
			g.ScaleTransform(0.8f, 0.8f);
			Draw(g);
		}

		private void Button6_Click_1(object sender, System.EventArgs e)
		{
			//取消运行
			this.Dispose();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -