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

📄 form1.cs

📁 原代码详细说明是关于c++方面的希望可以帮助大家使用
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Exam4_2
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.ComboBox comboBox2;
		private System.Windows.Forms.ComboBox comboBox3;
		/// <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 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.comboBox2 = new System.Windows.Forms.ComboBox();
			this.comboBox3 = new System.Windows.Forms.ComboBox();
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(24, 16);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(64, 56);
			this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			this.pictureBox1.MouseHover += new System.EventHandler(this.pictureBox1_MouseHover);
			this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
			this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave);
			this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "北京",
														   "上海",
														   "天津",
														   "大连"});
			this.comboBox1.Location = new System.Drawing.Point(72, 80);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(64, 20);
			this.comboBox1.TabIndex = 1;
			this.comboBox1.Text = "comboBox1";
			// 
			// comboBox2
			// 
			this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.Simple;
			this.comboBox2.Items.AddRange(new object[] {
														   "北京",
														   "上海",
														   "天津",
														   "大连"});
			this.comboBox2.Location = new System.Drawing.Point(144, 80);
			this.comboBox2.Name = "comboBox2";
			this.comboBox2.Size = new System.Drawing.Size(72, 72);
			this.comboBox2.TabIndex = 2;
			this.comboBox2.Text = "comboBox2";
			// 
			// comboBox3
			// 
			this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox3.Items.AddRange(new object[] {
														   "北京",
														   "上海",
														   "天津",
														   "大连"});
			this.comboBox3.Location = new System.Drawing.Point(224, 80);
			this.comboBox3.Name = "comboBox3";
			this.comboBox3.Size = new System.Drawing.Size(64, 20);
			this.comboBox3.TabIndex = 3;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(304, 157);
			this.Controls.Add(this.comboBox3);
			this.Controls.Add(this.comboBox2);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.pictureBox1);
			this.Name = "Form1";
			this.Text = "利用鼠标和键盘控制图片显示";
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
			this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseWheel);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			this.Text=String.Concat("当前鼠标位置:","(",e.X.ToString(),",",e.Y.ToString(),")");
		}

		private void pictureBox1_MouseHover(object sender, System.EventArgs e)
		{
			this.Text="单击左键放大图片,单击右键缩小图片,用光标移动图片";
		}

		private void pictureBox1_MouseLeave(object sender, System.EventArgs e)
		{
		    this.Text="利用鼠标和键盘控制图片显示";
		}

		private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			double scale=1.0;
			if(e.Button==MouseButtons.Left)scale=1.1;
			if(e.Button==MouseButtons.Right)scale=0.9;
            pictureBox1.Size=new System.Drawing.Size((int)(pictureBox1.Width*scale),(int)(pictureBox1.Height*scale));
		}
		private void Form1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
		{
		    System.Drawing.Point pt=pictureBox1.Location;
			pt.Y-=e.Delta/10;
			pictureBox1.Location=pt;
			System.Console.WriteLine("sss");
		}
		private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
		    int nXStep=0,nYStep=0;
            System.Drawing.Point pt=pictureBox1.Location;
			String str,strShift,strCtrl,strAlt;
			switch(e.KeyData)
			{
				case System.Windows.Forms.Keys.Up:
					nYStep=-1;break;
				case System.Windows.Forms.Keys.Down:
					nYStep=1;break;
				case System.Windows.Forms.Keys.Left:
					nXStep=-1;break;
				case System.Windows.Forms.Keys.Right:
					nXStep=1;break;
				default:
					if(e.Shift)strShift="Shift+";
					else strShift="";
					if(e.Control)strCtrl="Ctrl+";
					else strCtrl="";
					if(e.Alt)strAlt="Alt+";
					else strAlt="";
					str=String.Concat("KeyDown:",strShift,strCtrl,strAlt,e.KeyCode);
					this.Text=str;
			        break;
			}
			if(nXStep!=0||nYStep!=0)
			{
				pt.X+=nXStep;
				pt.Y+=nYStep;
				pictureBox1.Location=pt;
			}
		}
		private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
		    System.Console.WriteLine(e.KeyChar);
			if(e.KeyChar==(char)27)this.Close();
		}

	}
}

⌨️ 快捷键说明

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