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

📄 form1.cs

📁 c#程序部分代码我没有用过是我的老师给我的用于arcGIS engine 开发的
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace cs_MouseEvent
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox picColor;
		private System.Windows.Forms.TrackBar tkbRed;
		private System.Windows.Forms.TrackBar tkbBlue;
		private System.Windows.Forms.TrackBar tkbGreen;
		private System.Windows.Forms.PictureBox picShow;
		/// <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.picColor = new System.Windows.Forms.PictureBox();
			this.tkbRed = new System.Windows.Forms.TrackBar();
			this.tkbBlue = new System.Windows.Forms.TrackBar();
			this.tkbGreen = new System.Windows.Forms.TrackBar();
			this.picShow = new System.Windows.Forms.PictureBox();
			((System.ComponentModel.ISupportInitialize)(this.tkbRed)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.tkbBlue)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.tkbGreen)).BeginInit();
			this.SuspendLayout();
			// 
			// picColor
			// 
			this.picColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.picColor.Location = new System.Drawing.Point(16, 24);
			this.picColor.Name = "picColor";
			this.picColor.Size = new System.Drawing.Size(64, 104);
			this.picColor.TabIndex = 0;
			this.picColor.TabStop = false;
			// 
			// tkbRed
			// 
			this.tkbRed.BackColor = System.Drawing.Color.Red;
			this.tkbRed.Location = new System.Drawing.Point(96, 16);
			this.tkbRed.Maximum = 255;
			this.tkbRed.Name = "tkbRed";
			this.tkbRed.Size = new System.Drawing.Size(264, 45);
			this.tkbRed.TabIndex = 1;
			this.tkbRed.Scroll += new System.EventHandler(this.DisplayRGB);
			// 
			// tkbBlue
			// 
			this.tkbBlue.BackColor = System.Drawing.Color.Blue;
			this.tkbBlue.Location = new System.Drawing.Point(96, 96);
			this.tkbBlue.Maximum = 255;
			this.tkbBlue.Name = "tkbBlue";
			this.tkbBlue.Size = new System.Drawing.Size(264, 45);
			this.tkbBlue.TabIndex = 2;
			this.tkbBlue.Scroll += new System.EventHandler(this.DisplayRGB);
			// 
			// tkbGreen
			// 
			this.tkbGreen.BackColor = System.Drawing.Color.Lime;
			this.tkbGreen.Location = new System.Drawing.Point(96, 56);
			this.tkbGreen.Maximum = 255;
			this.tkbGreen.Name = "tkbGreen";
			this.tkbGreen.Size = new System.Drawing.Size(264, 45);
			this.tkbGreen.TabIndex = 3;
			this.tkbGreen.Scroll += new System.EventHandler(this.DisplayRGB);
			// 
			// picShow
			// 
			this.picShow.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.picShow.Location = new System.Drawing.Point(16, 160);
			this.picShow.Name = "picShow";
			this.picShow.Size = new System.Drawing.Size(360, 168);
			this.picShow.TabIndex = 4;
			this.picShow.TabStop = false;
			this.picShow.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picShow_MouseMove);
			this.picShow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.picShow_MouseDown);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(400, 342);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.picShow,
																		  this.tkbGreen,
																		  this.tkbBlue,
																		  this.tkbRed,
																		  this.picColor});
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.tkbRed)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tkbBlue)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tkbGreen)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		Bitmap bmp = new Bitmap(432, 304);
		int OldX, OldY;
		int point;
		Color pen_c;

		private void Form1_Load(object sender, System.EventArgs e)
		{
			picColor.BackColor = Color.FromArgb(0, 0, 0);
			Graphics g = Graphics.FromImage(bmp);
			pen_c = Color.Black;
			point = 3;
			g.Clear(Color.White);
			picShow.Image = bmp;
			picShow.Refresh();	

		}

		private void picShow_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			OldX = e.X;
			OldY = e.Y;

		}

		private void picShow_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Left)
			{
				Graphics g = Graphics.FromImage(bmp);
				Pen p = new Pen(pen_c, point);
				g.DrawLine(p, OldX, OldY, e.X, e.Y);
				picShow.Image = bmp;
				OldX = e.X;
				OldY = e.Y;
			}		

		}
		private void DisplayRGB(object sender, System.EventArgs e)
		{
			picColor.BackColor = Color.FromArgb(tkbRed.Value,
				tkbGreen.Value, tkbBlue.Value);
			pen_c = Color.FromArgb(tkbRed.Value, tkbGreen.Value, tkbBlue.Value);
		}

	}
}

⌨️ 快捷键说明

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