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

namespace Northwind
{
	/// <summary>
	/// Summary description for frmBaseForm.
	/// </summary>
	public class frmBaseForm : System.Windows.Forms.Form
	{
		protected bool isCanceled=false;
		protected System.Windows.Forms.MainMenu mmMainMenu;
		protected System.Windows.Forms.MenuItem miFile;
		protected System.Windows.Forms.MenuItem miFOpen;
		protected System.Windows.Forms.MenuItem miFNew;
		private System.Windows.Forms.MenuItem miFClose;
		protected System.Windows.Forms.ImageList ilImages;
		protected System.Windows.Forms.ToolBar tbToolBar;
		protected System.Windows.Forms.ToolBarButton tbbOpen;
		protected System.Windows.Forms.ToolBarButton tbbNew;
		private System.Windows.Forms.StatusBar sbStatus;
		private System.Windows.Forms.StatusBarPanel sbpStatus;
		private System.Windows.Forms.StatusBarPanel sbpProgress;
		protected System.Windows.Forms.ErrorProvider epErrors;
		protected System.Windows.Forms.MenuItem mnuFSep1;
		private System.Windows.Forms.StatusBarPanel sbpCancelButton;
		private System.Windows.Forms.ProgressBar pbProgress;
		private System.Windows.Forms.Button btnCancelProgress;
		private System.ComponentModel.IContainer components;

		public frmBaseForm()
		{
			//
			// 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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmBaseForm));
			this.mmMainMenu = new System.Windows.Forms.MainMenu();
			this.miFile = new System.Windows.Forms.MenuItem();
			this.miFOpen = new System.Windows.Forms.MenuItem();
			this.miFNew = new System.Windows.Forms.MenuItem();
			this.mnuFSep1 = new System.Windows.Forms.MenuItem();
			this.miFClose = new System.Windows.Forms.MenuItem();
			this.ilImages = new System.Windows.Forms.ImageList(this.components);
			this.tbToolBar = new System.Windows.Forms.ToolBar();
			this.tbbOpen = new System.Windows.Forms.ToolBarButton();
			this.tbbNew = new System.Windows.Forms.ToolBarButton();
			this.sbStatus = new System.Windows.Forms.StatusBar();
			this.sbpStatus = new System.Windows.Forms.StatusBarPanel();
			this.sbpProgress = new System.Windows.Forms.StatusBarPanel();
			this.epErrors = new System.Windows.Forms.ErrorProvider();
			this.sbpCancelButton = new System.Windows.Forms.StatusBarPanel();
			this.pbProgress = new System.Windows.Forms.ProgressBar();
			this.btnCancelProgress = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.sbpStatus)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.sbpProgress)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.sbpCancelButton)).BeginInit();
			this.SuspendLayout();
			// 
			// mmMainMenu
			// 
			this.mmMainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					   this.miFile});
			// 
			// miFile
			// 
			this.miFile.Index = 0;
			this.miFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																				   this.miFOpen,
																				   this.miFNew,
																				   this.mnuFSep1,
																				   this.miFClose});
			this.miFile.Text = "&File";
			// 
			// miFOpen
			// 
			this.miFOpen.Index = 0;
			this.miFOpen.Text = "&Open";
			// 
			// miFNew
			// 
			this.miFNew.Index = 1;
			this.miFNew.Text = "&New";
			// 
			// mnuFSep1
			// 
			this.mnuFSep1.Index = 2;
			this.mnuFSep1.Text = "-";
			// 
			// miFClose
			// 
			this.miFClose.Index = 3;
			this.miFClose.Text = "&Close";
			this.miFClose.Click += new System.EventHandler(this.miFClose_Click);
			// 
			// ilImages
			// 
			this.ilImages.ImageSize = new System.Drawing.Size(16, 16);
			this.ilImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilImages.ImageStream")));
			this.ilImages.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tbToolBar
			// 
			this.tbToolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						 this.tbbOpen,
																						 this.tbbNew});
			this.tbToolBar.DropDownArrows = true;
			this.tbToolBar.ImageList = this.ilImages;
			this.tbToolBar.Location = new System.Drawing.Point(0, 0);
			this.tbToolBar.Name = "tbToolBar";
			this.tbToolBar.ShowToolTips = true;
			this.tbToolBar.Size = new System.Drawing.Size(542, 28);
			this.tbToolBar.TabIndex = 0;
			// 
			// tbbOpen
			// 
			this.tbbOpen.ImageIndex = 0;
			this.tbbOpen.ToolTipText = "Open";
			// 
			// tbbNew
			// 
			this.tbbNew.ImageIndex = 1;
			this.tbbNew.ToolTipText = "New";
			// 
			// sbStatus
			// 
			this.sbStatus.Location = new System.Drawing.Point(0, 444);
			this.sbStatus.Name = "sbStatus";
			this.sbStatus.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																						this.sbpStatus,
																						this.sbpCancelButton,
																						this.sbpProgress});
			this.sbStatus.ShowPanels = true;
			this.sbStatus.Size = new System.Drawing.Size(542, 22);
			this.sbStatus.TabIndex = 1;
			this.sbStatus.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.sbStatus_PanelClick);
			this.sbStatus.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.sbStatus_DrawItem);
			// 
			// sbpStatus
			// 
			this.sbpStatus.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.sbpStatus.Width = 326;
			// 
			// sbpProgress
			// 
			this.sbpProgress.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
			// 
			// epErrors
			// 
			this.epErrors.ContainerControl = this;
			// 
			// sbpCancelButton
			// 
			this.sbpCancelButton.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
			// 
			// pbProgress
			// 
			this.pbProgress.Location = new System.Drawing.Point(104, 384);
			this.pbProgress.Name = "pbProgress";
			this.pbProgress.TabIndex = 2;
			this.pbProgress.Visible = false;
			this.pbProgress.Click += new System.EventHandler(this.pbProgress_Click);
			// 
			// btnCancelProgress
			// 
			this.btnCancelProgress.Location = new System.Drawing.Point(104, 320);
			this.btnCancelProgress.Name = "btnCancelProgress";
			this.btnCancelProgress.TabIndex = 3;
			this.btnCancelProgress.Text = "Cancel";
			this.btnCancelProgress.Visible = false;
			this.btnCancelProgress.Click += new System.EventHandler(this.btnCancelProgress_Click);
			// 
			// frmBaseForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(542, 466);
			this.Controls.Add(this.btnCancelProgress);
			this.Controls.Add(this.pbProgress);
			this.Controls.Add(this.sbStatus);
			this.Controls.Add(this.tbToolBar);
			this.Menu = this.mmMainMenu;
			this.Name = "frmBaseForm";
			this.Text = "<Your Form Title Goes Here>";
			this.Load += new System.EventHandler(this.frmBaseForm_Load);
			((System.ComponentModel.ISupportInitialize)(this.sbpStatus)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.sbpProgress)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.sbpCancelButton)).EndInit();
			this.ResumeLayout(false);

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

		protected void SetStatusText()
		{
			SetStatusText(string.Empty);
		}
		private delegate void SetStatusTextDelegate(string StatusText);

		protected void SetStatusText(string StatusText)
		{
			if (InvokeRequired)
			{
				//marshall the call into the main UI thread
				BeginInvoke(new SetStatusTextDelegate (SetStatusText),new object[]{StatusText});
				return;
			}
			sbpStatus.Text = StatusText;
		}

		protected void UpdateProgress()
		{
			UpdateProgress(0);
		}

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

		private void sbStatus_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
		{
			if(sbdevent.Panel.Equals(sbpProgress))
			{
				Rectangle r = sbdevent.Bounds;
				r.Inflate (1,1);
				pbProgress.Bounds = r;
			}
			else if (sbdevent.Panel.Equals(sbpCancelButton))
			{
				Rectangle r  = sbdevent.Bounds;
				r.Inflate (1,1);
				btnCancelProgress.Bounds = r;
			}
		}

		private void frmBaseForm_Load(object sender, System.EventArgs e)
		{
			sbStatus.Controls.Add(btnCancelProgress);
			sbStatus.Controls.Add(pbProgress);
		}

		private void sbStatus_PanelClick(object sender, System.Windows.Forms.StatusBarPanelClickEventArgs e)
		{
		
		}

		private void btnCancelProgress_Click(object sender, System.EventArgs e)
		{
			isCanceled=true;

		}
		private delegate void UpdateProgressDelegate(Single PercentDone);

		protected void UpdateProgress(Single PercentDone)
		{
			if(InvokeRequired)
			{
				//marshall the call into the Main UI thread...
				BeginInvoke(new UpdateProgressDelegate (UpdateProgress),new object [] {PercentDone});
				return;
			}
			if (0==PercentDone) isCanceled = true;
			btnCancelProgress.Visible =!isCanceled;
			pbProgress.Visible=!isCanceled;
			pbProgress.Value = (int)PercentDone;
			sbpStatus.Text=pbProgress.Value + " % complete";
			if(0==PercentDone)
				sbpStatus.Text = string.Empty;

		}
	}
}
