?? formphotopath.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 + -