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.CheckBox Check7;
		public System.Windows.Forms.CheckBox Check6;
		public System.Windows.Forms.CheckBox Check3;
		public System.Windows.Forms.CheckBox Check2;
		public System.Windows.Forms.GroupBox Frame3;
		public System.Windows.Forms.GroupBox Frame2;
		public System.Windows.Forms.CheckBox Check5;
		public System.Windows.Forms.CheckBox Check4;
		public System.Windows.Forms.ComboBox Combo1;
		public System.Windows.Forms.CheckBox Check1;
		public System.Windows.Forms.Label Label1;
		public System.Windows.Forms.GroupBox Frame1;
		public System.Windows.Forms.TextBox Text2;
		public System.Windows.Forms.TextBox Text1;
		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.Check7 = new System.Windows.Forms.CheckBox();
			this.Check6 = new System.Windows.Forms.CheckBox();
			this.Check3 = new System.Windows.Forms.CheckBox();
			this.Check2 = new System.Windows.Forms.CheckBox();
			this.Frame3 = new System.Windows.Forms.GroupBox();
			this.Frame2 = new System.Windows.Forms.GroupBox();
			this.Check5 = new System.Windows.Forms.CheckBox();
			this.Check4 = new System.Windows.Forms.CheckBox();
			this.Combo1 = new System.Windows.Forms.ComboBox();
			this.Check1 = new System.Windows.Forms.CheckBox();
			this.Label1 = new System.Windows.Forms.Label();
			this.Frame1 = new System.Windows.Forms.GroupBox();
			this.Text2 = new System.Windows.Forms.TextBox();
			this.Text1 = new System.Windows.Forms.TextBox();
			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();
			this.Frame2.SuspendLayout();
			this.Frame1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).BeginInit();
			this.SuspendLayout();
			// 
			// Check7
			// 
			this.Check7.BackColor = System.Drawing.SystemColors.Control;
			this.Check7.Cursor = System.Windows.Forms.Cursors.Default;
			this.Check7.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Check7.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Check7.Location = new System.Drawing.Point(464, 252);
			this.Check7.Name = "Check7";
			this.Check7.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Check7.Size = new System.Drawing.Size(97, 17);
			this.Check7.TabIndex = 28;
			this.Check7.Text = "Strikethrough";
			// 
			// Check6
			// 
			this.Check6.BackColor = System.Drawing.SystemColors.Control;
			this.Check6.Cursor = System.Windows.Forms.Cursors.Default;
			this.Check6.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Check6.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Check6.Location = new System.Drawing.Point(464, 236);
			this.Check6.Name = "Check6";
			this.Check6.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Check6.Size = new System.Drawing.Size(73, 17);
			this.Check6.TabIndex = 27;
			this.Check6.Text = "Underline";
			// 
			// Check3
			// 
			this.Check3.BackColor = System.Drawing.SystemColors.Control;
			this.Check3.Cursor = System.Windows.Forms.Cursors.Default;
			this.Check3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Check3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Check3.Location = new System.Drawing.Point(480, 356);
			this.Check3.Name = "Check3";
			this.Check3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Check3.Size = new System.Drawing.Size(81, 17);
			this.Check3.TabIndex = 26;
			this.Check3.Text = "Clip Text";
			// 
			// Check2
			// 
			this.Check2.BackColor = System.Drawing.SystemColors.Control;
			this.Check2.Cursor = System.Windows.Forms.Cursors.Default;
			this.Check2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Check2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Check2.Location = new System.Drawing.Point(480, 332);
			this.Check2.Name = "Check2";
			this.Check2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Check2.Size = new System.Drawing.Size(81, 25);
			this.Check2.TabIndex = 25;
			this.Check2.Text = "Scale Fonts";
			// 
			// Frame3
			// 
			this.Frame3.BackColor = System.Drawing.SystemColors.Control;
			this.Frame3.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Frame3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame3.Location = new System.Drawing.Point(464, 316);
			this.Frame3.Name = "Frame3";
			this.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame3.Size = new System.Drawing.Size(129, 65);
			this.Frame3.TabIndex = 24;
			this.Frame3.TabStop = false;
			this.Frame3.Text = "Method Parameters";
			// 
			// Frame2
			// 
			this.Frame2.BackColor = System.Drawing.SystemColors.Control;
			this.Frame2.Controls.Add(this.Check5);
			this.Frame2.Controls.Add(this.Check4);
			this.Frame2.Controls.Add(this.Combo1);
			this.Frame2.Controls.Add(this.Check1);
			this.Frame2.Controls.Add(this.Label1);
			this.Frame2.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Frame2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame2.Location = new System.Drawing.Point(456, 180);
			this.Frame2.Name = "Frame2";
			this.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame2.Size = new System.Drawing.Size(137, 129);
			this.Frame2.TabIndex = 23;
			this.Frame2.TabStop = false;
			this.Frame2.Text = "Some Text Properties";
			// 
			// Check5
			// 
			this.Check5.BackColor = System.Drawing.SystemColors.Control;
			this.Check5.Cursor = System.Windows.Forms.Cursors.Default;
			this.Check5.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Check5.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Check5.Location = new System.Drawing.Point(72, 40);
			this.Check5.Name = "Check5";
			this.Check5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Check5.Size = new System.Drawing.Size(49, 17);
			this.Check5.TabIndex = 12;
			this.Check5.Text = "Italic";
			// 
			// Check4
			// 
			this.Check4.BackColor = System.Drawing.SystemColors.Control;
			this.Check4.Cursor = System.Windows.Forms.Cursors.Default;
			this.Check4.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Check4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Check4.Location = new System.Drawing.Point(8, 40);
			this.Check4.Name = "Check4";
			this.Check4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Check4.Size = new System.Drawing.Size(49, 17);
			this.Check4.TabIndex = 11;
			this.Check4.Text = "Bold";
			// 
			// Combo1
			// 
			this.Combo1.BackColor = System.Drawing.SystemColors.Window;
			this.Combo1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Combo1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Combo1.ForeColor = System.Drawing.SystemColors.WindowText;
			this.Combo1.Items.AddRange(new object[] {
														"12",
														"24",
														"36",
														"48",
														"72"});
			this.Combo1.Location = new System.Drawing.Point(72, 96);
			this.Combo1.Name = "Combo1";
			this.Combo1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Combo1.Size = new System.Drawing.Size(57, 22);
			this.Combo1.TabIndex = 10;
			this.Combo1.Text = "24";
			// 
			// Check1
			// 
			this.Check1.BackColor = System.Drawing.SystemColors.Control;
			this.Check1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Check1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Check1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Check1.Location = new System.Drawing.Point(8, 16);
			this.Check1.Name = "Check1";
			this.Check1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Check1.Size = new System.Drawing.Size(121, 25);
			this.Check1.TabIndex = 8;
			this.Check1.Text = "Transparent Back";
			// 
			// Label1
			// 
			this.Label1.BackColor = System.Drawing.SystemColors.Control;
			this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label1.Location = new System.Drawing.Point(8, 96);
			this.Label1.Name = "Label1";
			this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label1.Size = new System.Drawing.Size(56, 17);
			this.Label1.TabIndex = 9;
			this.Label1.Text = "Font Size";
			// 
			// Frame1
			// 
			this.Frame1.BackColor = System.Drawing.SystemColors.Control;
			this.Frame1.Controls.Add(this.Text2);
			this.Frame1.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame1.Location = new System.Drawing.Point(456, 124);
			this.Frame1.Name = "Frame1";
			this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame1.Size = new System.Drawing.Size(137, 49);
			this.Frame1.TabIndex = 22;
			this.Frame1.TabStop = false;
			this.Frame1.Text = "Enter Text";
			// 
			// Text2
			// 
			this.Text2.AcceptsReturn = true;
			this.Text2.AutoSize = false;
			this.Text2.BackColor = System.Drawing.SystemColors.Window;
			this.Text2.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.Text2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Text2.ForeColor = System.Drawing.SystemColors.WindowText;
			this.Text2.Location = new System.Drawing.Point(8, 16);
			this.Text2.MaxLength = 0;
			this.Text2.Name = "Text2";
			this.Text2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Text2.Size = new System.Drawing.Size(105, 25);
			this.Text2.TabIndex = 6;
			this.Text2.Text = "ImageKit";
			// 
			// 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(8, 0);
			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(585, 49);
			this.Text1.TabIndex = 21;
			this.Text1.Text = @"This sample uses the DrawText method. The DrawText method draws text within a specified rectangle. Select an area on the image with your mouse and click the ""Draw Text"" button. In this sample, only a few PrintDraw properties are used. For a full description of the method and applicable properties, please refer to the Help documentation.";
			// 
			// 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(464, 436);
			this.Command3.Name = "Command3";
			this.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command3.Size = new System.Drawing.Size(129, 41);
			this.Command3.TabIndex = 20;
			this.Command3.Text = "End";
			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(464, 388);
			this.Command2.Name = "Command2";
			this.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command2.Size = new System.Drawing.Size(129, 41);
			this.Command2.TabIndex = 19;
			this.Command2.Text = "Draw Text";
			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(456, 68);
			this.Command1.Name = "Command1";
			this.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command1.Size = new System.Drawing.Size(137, 41);
			this.Command1.TabIndex = 18;
			this.Command1.Text = "Load Image";
			this.Command1.Click += new System.EventHandler(this.Command1_Click);
			// 
			// ImageKit1
			// 
			this.ImageKit1.Location = new System.Drawing.Point(8, 56);
			this.ImageKit1.Name = "ImageKit1";
			this.ImageKit1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit1.OcxState")));
			this.ImageKit1.Size = new System.Drawing.Size(441, 409);
			this.ImageKit1.TabIndex = 29;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(601, 480);
			this.Controls.Add(this.ImageKit1);
			this.Controls.Add(this.Check7);
			this.Controls.Add(this.Check6);
			this.Controls.Add(this.Check3);
			this.Controls.Add(this.Check2);
			this.Controls.Add(this.Frame3);
			this.Controls.Add(this.Frame2);
			this.Controls.Add(this.Frame1);
			this.Controls.Add(this.Text1);
			this.Controls.Add(this.Command3);
			this.Controls.Add(this.Command2);
			this.Controls.Add(this.Command1);
			this.Name = "Form1";
			this.Text = "DrawText Method";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.Frame2.ResumeLayout(false);
			this.Frame1.ResumeLayout(false);
			((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);
			
			//check to see that the loaded image is a raster image...
			if (ImageKit1.ImageKind != IMAGEKIT7Lib.ImageKindConstants.ikRasterImage) 
			{
				ImageKit1.FreeMemory(ImageKit1.ImageHandle);
				MessageBox.Show("Please load a raster image");
				return;
			}
            
			
			//displays the image in scale display mode...
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale);
		}

		private void Command2_Click(object sender, System.EventArgs e)
		{
			bool ret;
			int RectLeft;
			int RectTop;
			int RectRight;
			int RectBottom;
			bool FontScale;
			bool Clip;
			
			//make sure an area is selected on the image...
			if (ImageKit1.RectRight == 0) 
			{
				MessageBox.Show("Please use your mouse to set the text area");
			}

			
			//retreive the coordinates of the area selected with the mouse...
			RectLeft = ImageKit1.RectLeft;
			RectTop = ImageKit1.RectTop;
			RectRight = ImageKit1.RectRight;
			RectBottom = ImageKit1.RectBottom;
			
			//reset the PrintDraw interface's property values...
			ImageKit1.PrintDraw.ClearProperty();
			
			//set some properies necessary for the DrawText method...
			ImageKit1.PrintDraw.Text = Text2.Text;
			ImageKit1.PrintDraw.FontName = "Arial";
			ImageKit1.PrintDraw.FontSize = Convert.ToInt16(Combo1.Text);
			
			//transparent background
			if (Check1.Checked==true) 
			{
				ImageKit1.PrintDraw.Transparent = true;
			}
			else 
			{
				ImageKit1.PrintDraw.Transparent = false;
			}
			
			//scale the text to fit inside the selected area...
			if (Check2.Checked==true) 
			{
				FontScale = true;
			}
			else 
			{
				FontScale = false;
			}
			
			//clip the text if it doesn't fit...
			if (Check3.Checked==true) 
			{
				Clip = true;
			}
			else 
			{
				Clip = false;
			}
			
			//bold...
			if (Check4.Checked==true) 
			{
				ImageKit1.PrintDraw.FontBold = true;
			}
			else 
			{
				ImageKit1.PrintDraw.FontBold = false;
			}
			
			//Italic...
			if (Check5.Checked==true) 
			{
				ImageKit1.PrintDraw.FontItalic = true;
			}
			else 
			{
				ImageKit1.PrintDraw.FontItalic = false;
			}
			
			//Underline
			if (Check6.Checked==true) 
			{
				ImageKit1.PrintDraw.FontUnderline = true;
			}
			else 
			{
				ImageKit1.PrintDraw.FontUnderline = false;
			}
			
			//strike through
			if (Check7.Checked==true) 
			{
				ImageKit1.PrintDraw.FontStrikeOut = true;
			}
			else 
			{
				ImageKit1.PrintDraw.FontStrikeOut = false;
			}
			
			//set the text color and background color
			ImageKit1.PrintDraw.TextColor1 = System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Red);
			ImageKit1.PrintDraw.TextColor2 = System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Yellow);
			
			//execute the DrawText method, drawing directly to the image handle.
			//See the help file for a full discussion of the DrawText parameters...
			ret = ImageKit1.PrintDraw.DrawText(ImageKit1.ImageHandle, RectLeft, RectTop, RectRight, RectBottom, FontScale, Clip, IMAGEKIT7Lib.OutPutDeviceModeConstants.ikMemoryHandle);
			
			
			//reset selected area
			RectLeft = 0;
			RectTop = 0;
			RectRight = 0;
			RectBottom = 0;
			
			//redisplay the image so the the text will appear on the screen...
			ImageKit1.CtlRefresh();
		}

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

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//all an area to be selected with the mouse
			ImageKit1.RectDraw = true;
		}
	}
}
