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

namespace Project1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		public System.Windows.Forms.TextBox Text1;
		public System.Windows.Forms.Button Command5;
		public System.Windows.Forms.Button Command4;
		public System.Windows.Forms.Button Command3;
		public System.Windows.Forms.Button Command2;
		public System.Windows.Forms.Button Command1;
		private AxIMAGEKIT7Lib.AxImageKit ImageKit1;
		/// <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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.Text1 = new System.Windows.Forms.TextBox();
			this.Command5 = new System.Windows.Forms.Button();
			this.Command4 = new System.Windows.Forms.Button();
			this.Command3 = new System.Windows.Forms.Button();
			this.Command2 = new System.Windows.Forms.Button();
			this.Command1 = new System.Windows.Forms.Button();
			this.ImageKit1 = new AxIMAGEKIT7Lib.AxImageKit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).BeginInit();
			this.SuspendLayout();
			// 
			// Text1
			// 
			this.Text1.AcceptsReturn = true;
			this.Text1.AutoSize = false;
			this.Text1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
			this.Text1.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.Text1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Text1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
			this.Text1.Location = new System.Drawing.Point(7, 4);
			this.Text1.MaxLength = 0;
			this.Text1.Multiline = true;
			this.Text1.Name = "Text1";
			this.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Text1.Size = new System.Drawing.Size(553, 65);
			this.Text1.TabIndex = 12;
			this.Text1.Text = @"After you have edited an image, you must transfer the modifications to the ImageHandle before they can be saved. The Edit interface (Image-Editing Toolbars) writes modifications to the ImageHdc. To transfer that to the ImageHandle, you need to call the Modify method. The PrintDraw interface allows you to write directly to the ImageHandle or to use the ImageHdc and the Modify method combination.";
			// 
			// Command5
			// 
			this.Command5.BackColor = System.Drawing.SystemColors.Control;
			this.Command5.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command5.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command5.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command5.Location = new System.Drawing.Point(447, 404);
			this.Command5.Name = "Command5";
			this.Command5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command5.Size = new System.Drawing.Size(113, 41);
			this.Command5.TabIndex = 11;
			this.Command5.Text = "End";
			this.Command5.Click += new System.EventHandler(this.Command5_Click);
			// 
			// Command4
			// 
			this.Command4.BackColor = System.Drawing.SystemColors.Control;
			this.Command4.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command4.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command4.Location = new System.Drawing.Point(447, 348);
			this.Command4.Name = "Command4";
			this.Command4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command4.Size = new System.Drawing.Size(113, 41);
			this.Command4.TabIndex = 10;
			this.Command4.Text = "Save Image";
			this.Command4.Click += new System.EventHandler(this.Command4_Click);
			// 
			// Command3
			// 
			this.Command3.BackColor = System.Drawing.SystemColors.Control;
			this.Command3.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command3.Location = new System.Drawing.Point(447, 228);
			this.Command3.Name = "Command3";
			this.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command3.Size = new System.Drawing.Size(113, 57);
			this.Command3.TabIndex = 9;
			this.Command3.Text = "Draw Red Line To ImageHdc And Call Modify Method";
			this.Command3.Click += new System.EventHandler(this.Command3_Click);
			// 
			// Command2
			// 
			this.Command2.BackColor = System.Drawing.SystemColors.Control;
			this.Command2.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command2.Location = new System.Drawing.Point(447, 156);
			this.Command2.Name = "Command2";
			this.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command2.Size = new System.Drawing.Size(113, 57);
			this.Command2.TabIndex = 8;
			this.Command2.Text = "Draw Blue Line To Image Handle";
			this.Command2.Click += new System.EventHandler(this.Command2_Click);
			// 
			// Command1
			// 
			this.Command1.BackColor = System.Drawing.SystemColors.Control;
			this.Command1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command1.Location = new System.Drawing.Point(447, 76);
			this.Command1.Name = "Command1";
			this.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command1.Size = new System.Drawing.Size(113, 41);
			this.Command1.TabIndex = 7;
			this.Command1.Text = "Load Image";
			this.Command1.Click += new System.EventHandler(this.Command1_Click);
			// 
			// ImageKit1
			// 
			this.ImageKit1.Location = new System.Drawing.Point(8, 72);
			this.ImageKit1.Name = "ImageKit1";
			this.ImageKit1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit1.OcxState")));
			this.ImageKit1.Size = new System.Drawing.Size(433, 369);
			this.ImageKit1.TabIndex = 13;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(566, 449);
			this.Controls.Add(this.ImageKit1);
			this.Controls.Add(this.Text1);
			this.Controls.Add(this.Command5);
			this.Controls.Add(this.Command4);
			this.Controls.Add(this.Command3);
			this.Controls.Add(this.Command2);
			this.Controls.Add(this.Command1);
			this.Name = "Form1";
			this.Text = "Saving Image Modifications";
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

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

		private void Command1_Click(object sender, System.EventArgs e)
		{
			//displays the 'Open File' dialog and allows you to select an image to load...
			if (ImageKit1.File.OpenFileDialog() == false) 
			{
				return;
			}
		
			//loads the image...
			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);
		
			//displays the image in scale display mode...
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale);
		}

		private void Command2_Click(object sender, System.EventArgs e)
		{
			bool ret;
		
			//reset the PrintDraw interface's property values...
			ImageKit1.PrintDraw.ClearProperty();
			
			//set some properties necessary for the Line method...
			ImageKit1.PrintDraw.PenColor = System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Blue);
			ImageKit1.PrintDraw.PenWidth = 10;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			
			//execute the Line method, drawing the line to the ImageHandle
			ret = ImageKit1.PrintDraw.Line(ImageKit1.ImageHandle, 10, 150, 150, 10, IMAGEKIT7Lib.OutPutDeviceModeConstants.ikMemoryHandle);
			//redisplay the image so the the text will appear on the screen...
			ImageKit1.CtlRefresh();
		}

		private void Command3_Click(object sender, System.EventArgs e)
		{
			bool ret;
		
			//enable editing...
			ImageKit1.Edit.EditEnable = true;
			
			//set some properties necessary for the Line method...
			ImageKit1.PrintDraw.PenColor = System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Red);
			ImageKit1.PrintDraw.PenWidth = 10;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			
			//execute the Line method, drawing the line to the ImageHdc
			// Note: because the DeviceMode parameter is set to ikScreen,
			//       the line is drawn in pixels...
			ret = ImageKit1.PrintDraw.Line(ImageKit1.ImageHdc, 10, 10, 150, 150, IMAGEKIT7Lib.OutPutDeviceModeConstants.ikScreen);
			
			//execute the Modify method to transfer the data from the ImageHdc to the ImageHandle...
			ImageKit1.Edit.Modify();
			
			//redisplay the image so the the text will appear on the screen...
			ImageKit1.CtlRefresh();
			
			//turn off editing
			ImageKit1.Edit.EditEnable = false;
		}

		private void Command4_Click(object sender, System.EventArgs e)
		{
			//exit if there is no image loaded...
			if (ImageKit1.ImageHandle == 0) 
			{
				return;
			}		
			//set the file extensions that are displayed in the "Save" file dialog.
			ImageKit1.File.FileExt = "*;BMP;JPG;GIF;";
		
			//display the "Save" file dialog...
			if (ImageKit1.File.SaveFileDialog() == false)
			{
				return;
			}

			//use the value of the SaveFileDlgFileType to determine the SaveFile method...
			switch (ImageKit1.File.SaveFileDlgFileType)
			{
			
				case IMAGEKIT7Lib.SaveFileDlgFileTypeConstants.ikSaveDlgBMP:
					//save as uncompressed bmp...
					ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveBMP, 0);
					break;
				
				case IMAGEKIT7Lib.SaveFileDlgFileTypeConstants.ikSaveDlgJPEG:
					//save as jpeg. Must check the bitcount and don't forget the JpegQuality!
					if (ImageKit1.BitCount == 24) 
					{
						ImageKit1.File.JpegQuality = 70;
						ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveJPEG, 0);
					}
					else if (ImageKit1.BitCount == 8) 
					{
						if (ImageKit1.Gray != false) 
						{
							ImageKit1.File.JpegQuality = 70;
							ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveJPEG, 0);
						}
					}

					else 
					{
						MessageBox.Show("Jpeg images must be 24 bit color or 8 bit grayscale");
						return;
					}
					break;
				
				case IMAGEKIT7Lib.SaveFileDlgFileTypeConstants.ikSaveDlgGIF:
					//save as gif. Must check the bitcount!
					if (ImageKit1.BitCount > 8) 
					{
						MessageBox.Show("Gif images must be 256 colors or less");
						return;
					}
					ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveGIF, 0);
					break;
			}
		}

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