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

📄 formphotopath.cs

📁 蓝山人事管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using System.Data .SqlClient ;
using System.IO;

namespace BlueHill.BlueHillWindows.EmployeeManagement
{
	/// <summary>
	/// FormPhotoPath 的摘要说明。
	/// </summary>
	public class FormPhotoPath : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox TxtPhotoPath;
		private System.Windows.Forms.Button btnOpenDialog;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.OpenFileDialog OpenFileDialogPhoto;
	    public System.Windows.Forms.PictureBox picPhoto;
		public byte[] imgb;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormPhotoPath()
		{
			//
			// 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(FormPhotoPath));
			this.picPhoto = new System.Windows.Forms.PictureBox();
			this.panel1 = new System.Windows.Forms.Panel();
			this.btnOpenDialog = new System.Windows.Forms.Button();
			this.TxtPhotoPath = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.OpenFileDialogPhoto = new System.Windows.Forms.OpenFileDialog();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// picPhoto
			// 
			this.picPhoto.Image = ((System.Drawing.Image)(resources.GetObject("picPhoto.Image")));
			this.picPhoto.Location = new System.Drawing.Point(16, 16);
			this.picPhoto.Name = "picPhoto";
			this.picPhoto.Size = new System.Drawing.Size(104, 128);
			this.picPhoto.TabIndex = 0;
			this.picPhoto.TabStop = false;
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.btnOpenDialog);
			this.panel1.Controls.Add(this.TxtPhotoPath);
			this.panel1.Controls.Add(this.label1);
			this.panel1.Location = new System.Drawing.Point(144, 8);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(328, 104);
			this.panel1.TabIndex = 1;
			// 
			// btnOpenDialog
			// 
			this.btnOpenDialog.Location = new System.Drawing.Point(264, 56);
			this.btnOpenDialog.Name = "btnOpenDialog";
			this.btnOpenDialog.Size = new System.Drawing.Size(56, 23);
			this.btnOpenDialog.TabIndex = 2;
			this.btnOpenDialog.Text = "...";
			this.btnOpenDialog.Click += new System.EventHandler(this.btnOpenDialog_Click);
			// 
			// TxtPhotoPath
			// 
			this.TxtPhotoPath.Location = new System.Drawing.Point(8, 56);
			this.TxtPhotoPath.Name = "TxtPhotoPath";
			this.TxtPhotoPath.Size = new System.Drawing.Size(248, 21);
			this.TxtPhotoPath.TabIndex = 1;
			this.TxtPhotoPath.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "照片路径";
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(208, 128);
			this.btnOK.Name = "btnOK";
			this.btnOK.TabIndex = 2;
			this.btnOK.Text = "确定";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(320, 128);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 3;
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// FormPhotoPath
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(488, 189);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.picPhoto);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "FormPhotoPath";
			this.Text = "指定员工照片";
			this.Load += new System.EventHandler(this.FormPhotoPath_Load);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnOpenDialog_Click(object sender, System.EventArgs e)
		{
			try
			{   //设置文件名的字符串
				OpenFileDialogPhoto.Filter = @"images files|*.gif;*.jpg;*.bmp;*.jpeg|All files(*.*)|*.*";
				OpenFileDialogPhoto.ShowDialog();
				this.TxtPhotoPath.Text = OpenFileDialogPhoto.FileName;
				if(this.TxtPhotoPath.Text=="")
				{
					MessageBox.Show("没有选择到图片~~");
				}
				else
				{
					//从指定的文件创建 Image 对象。
					this.picPhoto.Image=Image.FromFile(this.TxtPhotoPath.Text);
				}
				
			}
			catch(Exception)
			{
				MessageBox.Show("请选择图片路径");
			}
		
		}

		private void FormPhotoPath_Load(object sender, System.EventArgs e)
		{
		
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			if (picPhoto.Text != "")
			{   //FileStream 类提供对文件的访问
				FileStream fs = File.OpenRead(this.picPhoto.Text);
				imgb = new byte[fs.Length];
				fs.Read(imgb, 0,imgb.Length);				
				fs.Close();
				this.Close();
			}
			else
			{
				MessageBox.Show("相片上传失败");
			}
		
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close ();
		}



	}
}

⌨️ 快捷键说明

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