using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace folderDialog
{
	/// <summary>
	/// Summary description for FolderDialog.
	/// </summary>
	public class FolderDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label lblFolder;
		private Microsoft.VisualBasic.Compatibility.VB6.DirListBox dirListBox;
		private Microsoft.VisualBasic.Compatibility.VB6.DriveListBox driveListBox;
		private Microsoft.VisualBasic.Compatibility.VB6.FileListBox fileListBox;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FolderDialog()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.dirListBox = new Microsoft.VisualBasic.Compatibility.VB6.DirListBox();
			this.driveListBox = new Microsoft.VisualBasic.Compatibility.VB6.DriveListBox();
			this.fileListBox = new Microsoft.VisualBasic.Compatibility.VB6.FileListBox();
			this.label1 = new System.Windows.Forms.Label();
			this.lblFolder = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.button1.Location = new System.Drawing.Point(200, 208);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(64, 23);
			this.button1.TabIndex = 0;
			this.button1.Text = "选择";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.button2.Location = new System.Drawing.Point(200, 240);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(64, 23);
			this.button2.TabIndex = 1;
			this.button2.Text = "取消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// dirListBox
			// 
			this.dirListBox.IntegralHeight = false;
			this.dirListBox.Location = new System.Drawing.Point(16, 48);
			this.dirListBox.Name = "dirListBox";
			this.dirListBox.Size = new System.Drawing.Size(120, 144);
			this.dirListBox.TabIndex = 2;
			this.dirListBox.SelectedIndexChanged += new System.EventHandler(this.dirListBox_Change);
			// 
			// driveListBox
			// 
			this.driveListBox.Location = new System.Drawing.Point(16, 16);
			this.driveListBox.Name = "driveListBox";
			this.driveListBox.Size = new System.Drawing.Size(121, 22);
			this.driveListBox.TabIndex = 3;
			this.driveListBox.SelectedIndexChanged += new System.EventHandler(this.driveListBox_SelectedIndexChanged_1);
			// 
			// fileListBox
			// 
			this.fileListBox.Location = new System.Drawing.Point(144, 16);
			this.fileListBox.Name = "fileListBox";
			this.fileListBox.Pattern = "*.*";
			this.fileListBox.Size = new System.Drawing.Size(136, 172);
			this.fileListBox.TabIndex = 4;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 208);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(128, 23);
			this.label1.TabIndex = 5;
			this.label1.Text = "你选了下面的文件夹：";
			// 
			// lblFolder
			// 
			this.lblFolder.Location = new System.Drawing.Point(24, 240);
			this.lblFolder.Name = "lblFolder";
			this.lblFolder.Size = new System.Drawing.Size(160, 23);
			this.lblFolder.TabIndex = 6;
			// 
			// FolderDialog
			// 
			this.AcceptButton = this.button1;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.CancelButton = this.button2;
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.lblFolder,
																		  this.label1,
																		  this.fileListBox,
																		  this.driveListBox,
																		  this.dirListBox,
																		  this.button2,
																		  this.button1});
			this.Name = "FolderDialog";
			this.Text = "打开文件夹";
			this.ResumeLayout(false);

		}
		#endregion

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

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

		  
		
		private void driveListBox_SelectedIndexChanged_1(object sender, System.EventArgs e)
		{
			string tempDrive="";
			try
			{
				this.dirListBox.Path = this.driveListBox.Drive;
				tempDrive= this.driveListBox.Drive;
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
				driveListBox.Drive = tempDrive;
			}
		}

		private void dirListBox_Change(object sender, System.EventArgs e)
		{
			try
			{
				this.fileListBox.Path = this.dirListBox.Path;
				this.lblFolder.Text = dirListBox.Path.Substring(dirListBox.Path.LastIndexOf("\\")+1);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error); 
			}
		}

		
    
		public string Path
		{
			get { return dirListBox.Path; }
		}  

	}
}
