using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using C1.C1Flash;


namespace Slide_NavButton
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private C1.C1Flash.C1FlashSlide c1FlashSlide1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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.c1FlashSlide1 = new C1.C1Flash.C1FlashSlide();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // c1FlashSlide1
            // 
            this.c1FlashSlide1.FirstButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.c1FlashSlide1.FirstButton.Location = new System.Drawing.Point(190, 371);
            this.c1FlashSlide1.FirstButton.Size = new System.Drawing.Size(62, 23);
            this.c1FlashSlide1.FirstButton.Text = "First";
            this.c1FlashSlide1.ImageIndex = 0;
            this.c1FlashSlide1.LastButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.c1FlashSlide1.LastButton.Location = new System.Drawing.Point(391, 371);
            this.c1FlashSlide1.LastButton.Size = new System.Drawing.Size(62, 23);
            this.c1FlashSlide1.LastButton.Text = "Last";
            this.c1FlashSlide1.NextButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.c1FlashSlide1.NextButton.Location = new System.Drawing.Point(324, 371);
            this.c1FlashSlide1.NextButton.Size = new System.Drawing.Size(62, 23);
            this.c1FlashSlide1.NextButton.Text = "Next";
            this.c1FlashSlide1.PageFooter.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.c1FlashSlide1.PageFooter.ForeColor = System.Drawing.Color.Purple;
            this.c1FlashSlide1.PageFooter.Location = new System.Drawing.Point(15, 374);
            this.c1FlashSlide1.PageFooter.Size = new System.Drawing.Size(158, 21);
            this.c1FlashSlide1.PageFooter.Text = "Navigation Buttons";
            this.c1FlashSlide1.PageHeader.Font = new System.Drawing.Font("Arial", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.c1FlashSlide1.PageHeader.ForeColor = System.Drawing.Color.Blue;
            this.c1FlashSlide1.PageHeader.Location = new System.Drawing.Point(79, 18);
            this.c1FlashSlide1.PageHeader.Size = new System.Drawing.Size(429, 31);
            this.c1FlashSlide1.PageHeader.Text = "ComponentOne Flash Slide Sample";
            this.c1FlashSlide1.PageNumber.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.c1FlashSlide1.PageNumber.ForeColor = System.Drawing.Color.Black;
            this.c1FlashSlide1.PageNumber.Location = new System.Drawing.Point(476, 376);
            this.c1FlashSlide1.PageNumber.Size = new System.Drawing.Size(51, 15);
            this.c1FlashSlide1.PageNumber.Text = "Page {0}";
            this.c1FlashSlide1.PrevButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.c1FlashSlide1.PrevButton.Location = new System.Drawing.Point(257, 371);
            this.c1FlashSlide1.PrevButton.Size = new System.Drawing.Size(62, 23);
            this.c1FlashSlide1.PrevButton.Text = "Back";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(94, 149);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(174, 49);
            this.button1.TabIndex = 0;
            this.button1.Text = "Create Flash Slide";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(6, 20);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(352, 32);
            this.label1.TabIndex = 1;
            this.label1.Text = "This sample demonstrates the methods of creating a slide show that has navigation" +
                " buttons.";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(6, 62);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(352, 29);
            this.label2.TabIndex = 2;
            this.label2.Text = "By default, the SlideMode is Manual. You can change it to Automatic in Slide Desi" +
                "gner.";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(6, 104);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(352, 29);
            this.label3.TabIndex = 3;
            this.label3.Text = "To pop up the Slide Designer, right click the slide component and select \"Design\"" +
                " menu item.";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(364, 217);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "ComponentOne C1Flash Sample - Slide";
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void LaunchViewer(string filename)
		{
			try
			{
				System.Diagnostics.Process.Start(filename);
			}
			catch (Exception e)
			{
				System.Diagnostics.Process.Start("IEXPLORE.EXE", filename);
			}
		}

		private void AddPage0()
		{
			// Create page 0
			FPage page = c1FlashSlide1.AddPage();

			Rectangle rect = new Rectangle(100, 100, 350, 80);
			string text = "This sample demonstrates how to create flash slide using C1FlashSlide component.";
			Font font = new Font("MS Sans Serif", 14);
			page.DrawString(text, font, Brushes.Black, rect);

			rect.Offset(0, 80);
			text = "Some of the pages are copied from other C1FlashCanvas samples.";
			page.DrawString(text, font, Brushes.Black, rect);

			rect.Offset(0, 80);
			text = "Press <Next> button to go next page.";
			page.DrawString(text, font, Brushes.Black, rect);
			font.Dispose();
		}

		private void AddPage1()
		{
			// Create page 1
			FPage page = c1FlashSlide1.AddPage();

			Rectangle rect = new Rectangle(100, 50, 350, 80);
			string text = "This page displays a JPEG image.";
			Font font = new Font("MS Sans Serif", 14);
			page.DrawString(text, font, Brushes.Black, rect);

			Assembly a = Assembly.GetExecutingAssembly();
			string an = a.GetName().Name;
			Bitmap bmp = new Bitmap(a.GetManifestResourceStream(an + ".golf.jpg"));

			page.DrawImage(bmp, new Point(100, 80));
			bmp.Dispose();
			font.Dispose();
		}

		private void AddPage2()
		{
			// Create page 2
			FPage page = c1FlashSlide1.AddPage();

			Rectangle clientRect = new Rectangle(0, 0, page.Width, page.Height);
			Rectangle chartRect = clientRect;
			chartRect.Inflate(-60, -60);

			// Draws the horizontal meter
			Rectangle rectMarker = new Rectangle(chartRect.Left, chartRect.Bottom - 30, chartRect.Width, 30);
			Point pt1 = new Point(rectMarker.Left, rectMarker.Bottom);
			Point pt2 = new Point(rectMarker.Right, rectMarker.Bottom);
			Pen pen = new Pen(Color.Red);
			page.DrawLine(pen, pt1, pt2);

			int divisions = rectMarker.Width / 20;
			int x = rectMarker.Left + 20;
			int tenBarSize = rectMarker.Height / 4;
			int fiveBarSize = rectMarker.Height / 6;
			int oneBarSize = rectMarker.Height / 12;
			StringFormat sf = new StringFormat(StringFormat.GenericDefault);
			sf.Alignment = StringAlignment.Center;
			Font font = this.Font;
			for (int i = 1; i < divisions; i++)
			{
				int barsize = oneBarSize;
				int barwidth = 1;
				if (i % 10 == 0)
				{
					barsize = tenBarSize;
					barwidth = 2;

					Rectangle rectMark = new Rectangle(x - 20, rectMarker.Bottom + 2, 40, 40);
					page.DrawString(i.ToString(), font, Brushes.Black, rectMark, sf);
				}
				else
				{
					if (i % 5 == 0)
						barsize = fiveBarSize;
				}

				pt1 = new Point(x, rectMarker.Bottom - barsize);
				pt2 = new Point(x, rectMarker.Bottom);

				pen.Width = barwidth;
				page.DrawLine(pen, pt1, pt2);

				x += 20;
			}

			// Draws the vertical meter
			rectMarker = new Rectangle(chartRect.Left, chartRect.Top, 30, chartRect.Height);
			pt1 = new Point(rectMarker.Left, rectMarker.Top);
			pt2 = new Point(rectMarker.Left, rectMarker.Bottom);
			pen.Width = 1;
			page.DrawLine(pen, pt1, pt2);

			sf.LineAlignment = StringAlignment.Center;
			divisions = rectMarker.Height / 10;
			int y = rectMarker.Bottom - 10;
			for (int i = 1; i < divisions; i++)
			{
				int barwidth = oneBarSize;
				int barsize = 1;
				if (i % 10 == 0)
				{
					barwidth = tenBarSize;
					barsize = 2;

					Rectangle rectMark = new Rectangle(rectMarker.Left - 40, y - 20, 40, 40);
					page.DrawString(i.ToString(), font, Brushes.Black, rectMark, sf);
				}
				else
				{
					if (i % 5 == 0)
						barwidth = fiveBarSize;
				}

				pt1 = new Point(rectMarker.Left, y);
				pt2 = new Point(rectMarker.Left + barwidth, y);

				pen.Width = barsize;
				page.DrawLine(pen, pt1, pt2);

				y -= 10;
			}

			// Draw the label
			Rectangle rectLabel = new Rectangle(200, 50, 160, 60);
			pen.Color = Color.Black;
			pen.Width = 1;
			page.FillRectangle(Brushes.LightSkyBlue, rectLabel);
			page.DrawRectangle(pen, rectLabel);

			rectLabel.Inflate(-10, -10);
			Rectangle rectBlue = rectLabel;
			rectBlue.Height = 10;

			Rectangle rectPanel = rectBlue;
			rectPanel.Width = 10;
			Font labelFont = new Font("System", 6);
			page.FillRectangle(Brushes.Blue, rectPanel);
			page.DrawString("Sample Line - 1", labelFont, Brushes.Black, new Point(rectPanel.Right + 5, rectPanel.Top - 2));

			Rectangle rectGreen = rectBlue;
			rectGreen.Offset(0, rectGreen.Height + 10);
			rectPanel = rectGreen;
			rectPanel.Width = 10;
			page.FillRectangle(Brushes.LightGreen, rectPanel);
			page.DrawString("Sample Line - 2", labelFont, Brushes.Black, new Point(rectPanel.Right + 5, rectPanel.Top - 2));

			pen.Width = 1;
			pen.Color = Color.Blue;
			Point[] points = new Point[6];
			points[0] = new Point(60, 320);
			points[1] = new Point(150, 260);
			points[2] = new Point(210, 300);
			points[3] = new Point(300, 120);
			points[4] = new Point(350, 230);
			points[5] = new Point(450, 120);
			page.DrawLines(pen, points);

			pen.Width = 3;
			pen.Color = Color.LightGreen;
			points[0] = new Point(60, 120);
			points[1] = new Point(150, 240);
			points[2] = new Point(210, 180);
			points[3] = new Point(300, 260);
			points[4] = new Point(350, 260);
			points[5] = new Point(450, 280);
			page.DrawLines(pen, points);
		}

		private void AddPage3()
		{
			// Create page 3
			FPage page = c1FlashSlide1.AddPage();

			page.ResetTransform(); 
			Point ptCenter = new Point(page.Width/2, page.Height/2);

			// Moves the cordination origin point to the center of the canvas.
			page.TranslateTransform(ptCenter.X, ptCenter.Y);
			Rectangle rect = new Rectangle(0, 0, 100, 40);
			for(int i = 0; i < 12; i++)
			{
				// Draws the rectangle with the same rectangle parameter
				page.DrawRectangle(Pens.Orange, rect);

				// Rotates the cordinition by 30 degrees
				page.RotateTransform(30);

				// Scales the cordinition
				page.ScaleTransform(1.075F, 1.075F);
			}

			// Resets the cordinate
			page.ResetTransform(); 

			for(int i = 0; i < 12; i++)
			{
				page.DrawRectangle(Pens.Green, rect);

				// Change the Transform
				Matrix m = page.Transform;
				m.Shear(0.1F, 0.1F);
				page.Transform = m;
			}
		}

		private string tempdir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

		private void button1_Click(object sender, System.EventArgs e)
		{
			c1FlashSlide1.Clean();

			this.AddPage0();
			this.AddPage1();
			this.AddPage2();
			this.AddPage3();

			c1FlashSlide1.RenderToFile(tempdir + @"\c1flash_slide_nb.swf");
			LaunchViewer(tempdir + @"\c1flash_slide_nb.swf");
		}
	}
}
