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

namespace Project1
{
	/// <summary>
	///
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private AxIMAGEKIT7Lib.AxImageKit ImageKit1;
		public System.Windows.Forms.TextBox Text1;
		public System.Windows.Forms.Button Command1;
		public System.Windows.Forms.Button Command2;
		public System.Windows.Forms.Button Command3;
		public System.Windows.Forms.Button Command4;
		/// <summary>
		///
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			//B
			//
			InitializeComponent();

			//
			//
			//
		}

		/// <summary>
		///
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		///
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.ImageKit1 = new AxIMAGEKIT7Lib.AxImageKit();
			this.Text1 = new System.Windows.Forms.TextBox();
			this.Command1 = new System.Windows.Forms.Button();
			this.Command2 = new System.Windows.Forms.Button();
			this.Command3 = new System.Windows.Forms.Button();
			this.Command4 = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).BeginInit();
			this.SuspendLayout();
			// 
			// ImageKit1
			// 
			this.ImageKit1.Location = new System.Drawing.Point(4, 88);
			this.ImageKit1.Name = "ImageKit1";
			this.ImageKit1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit1.OcxState")));
			this.ImageKit1.Size = new System.Drawing.Size(372, 332);
			this.ImageKit1.TabIndex = 12;
			this.ImageKit1.EndDispImage += new AxIMAGEKIT7Lib._IImageKitEvents_EndDispImageEventHandler(this.ImageKit1_EndDispImage);
			// 
			// 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(4, 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(497, 80);
			this.Text1.TabIndex = 13;
			this.Text1.Text = @"This sample illustrates a number of PrintDraw methods relating to drawing shapes and text. The shapes and text are drawn to the Hdc (the screen or the printer) and not to the ImageHdc (the image data itself). For more information about drawing to the image data, please refer to the image editing samples. Also in this sample, the SavePrintInfo method is used to display the ""Print Setup"" dialog and printer settings are saved to the printer information file.";
			// 
			// 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(384, 92);
			this.Command1.Name = "Command1";
			this.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command1.Size = new System.Drawing.Size(113, 65);
			this.Command1.TabIndex = 14;
			this.Command1.Text = "Load Image and Draw Objects to Hdc";
			this.Command1.Click += new System.EventHandler(this.Command1_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(384, 180);
			this.Command2.Name = "Command2";
			this.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command2.Size = new System.Drawing.Size(113, 65);
			this.Command2.TabIndex = 15;
			this.Command2.Text = "Set Print Properties";
			this.Command2.Click += new System.EventHandler(this.Command2_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(384, 268);
			this.Command3.Name = "Command3";
			this.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command3.Size = new System.Drawing.Size(113, 65);
			this.Command3.TabIndex = 16;
			this.Command3.Text = "Print";
			this.Command3.Click += new System.EventHandler(this.Command3_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(384, 356);
			this.Command4.Name = "Command4";
			this.Command4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command4.Size = new System.Drawing.Size(113, 57);
			this.Command4.TabIndex = 17;
			this.Command4.Text = "End";
			this.Command4.Click += new System.EventHandler(this.Command4_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(508, 430);
			this.Controls.Add(this.Command1);
			this.Controls.Add(this.Command2);
			this.Controls.Add(this.Command3);
			this.Controls.Add(this.Command4);
			this.Controls.Add(this.Text1);
			this.Controls.Add(this.ImageKit1);
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		///
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		


		

		

		private int RGB(byte r, byte g, byte b)
		{
			return (r | (g << 8) | (b << 16));
		}

		private void Disp(bool Screen, int hDC)
		{
			bool Ret;
			short r, g, b;
			int []x = new int[3];
			int []y = new int[3];
			short scl;
			IMAGEKIT7Lib.OutPutDeviceModeConstants DeviceMode; 																					 

			if (Screen == true)
			{
				scl = 1;
				DeviceMode = IMAGEKIT7Lib.OutPutDeviceModeConstants.ikScreen;
			}
			else
			{
				scl = 5;
				DeviceMode = IMAGEKIT7Lib.OutPutDeviceModeConstants.ikPrinter;
			}

			// ImageOut
			if (DeviceMode == IMAGEKIT7Lib.OutPutDeviceModeConstants.ikPrinter)
				Ret = ImageKit1.PrintDraw.ImageOut(hDC, ImageKit1.ImageHandle, 100, 100, 1000, 1000, true, true, DeviceMode);

			// DrawText
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.FontName = "arial";
			ImageKit1.PrintDraw.FontSize = 20;
			ImageKit1.PrintDraw.CharAngle = 180;
			ImageKit1.PrintDraw.Direction = 2;
			ImageKit1.PrintDraw.HCentering = 1;
			ImageKit1.PrintDraw.VCentering = 1;
			ImageKit1.PrintDraw.FontBold = true;
			ImageKit1.PrintDraw.FontItalic = true;
			ImageKit1.PrintDraw.Transparent = true;
			ImageKit1.PrintDraw.Text = "ImageKit";
			Ret = ImageKit1.PrintDraw.DrawText(hDC, 10 * scl, 10 * scl, 300 * scl, 200 * scl, true, true, DeviceMode);
			ImageKit1.PrintDraw.CharAngle = 0;
			Ret = ImageKit1.PrintDraw.DrawText(hDC, 50 * scl, 50 * scl, 300 * scl, 200 * scl, true, true, DeviceMode);

			// Line
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			Ret = ImageKit1.PrintDraw.Line(hDC, 10 * scl, 10 * scl, 145 * scl, 100 * scl, DeviceMode);

			// Rectangle
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			Ret = ImageKit1.PrintDraw.Rectangle(hDC, 10 * scl, 10 * scl, 300 * scl, 200 * scl, DeviceMode);

			//Rectangle(filled)
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.BrushStyle = IMAGEKIT7Lib.BrushStyleConstants.ikBrushSolid;
			ImageKit1.PrintDraw.BrushColor = RGB(255, 0, 0);
			Ret = ImageKit1.PrintDraw.Rectangle(hDC, 300 * scl, 200 * scl, 350 * scl, 250 * scl, DeviceMode);

			//Ellipse
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 2;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			Ret = ImageKit1.PrintDraw.Ellipse(hDC, 10 * scl, 10 * scl, 300 * scl, 200 * scl, DeviceMode);

			//SetPixel
			ImageKit1.PrintDraw.ClearProperty();
			Ret = ImageKit1.PrintDraw.SetPixel(hDC, 360 * scl, 260 * scl, RGB(255, 128, 64), DeviceMode);

			//GetPixel
			ImageKit1.PrintDraw.ClearProperty();
			r = g = b = 0;
			Ret = ImageKit1.PrintDraw.GetPixel(hDC, 360 * scl, 260 * scl, ref r, ref g, ref b, DeviceMode);

			//Paint
			ImageKit1.PrintDraw.ClearProperty();
			Ret = ImageKit1.PrintDraw.Paint(hDC, 29 * scl, 198 * scl, RGB(255, 255, 255), RGB(255, 128, 64), IMAGEKIT7Lib.PaintModeConstants.ikSurface, DeviceMode);

			//Polygon
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.PenColor = RGB(255, 0, 255);
			x[0] = 10 * scl; y[0] = 210 * scl;
			x[1] = 30 * scl; y[1] = 220 * scl;
			x[2] = 20 * scl; y[2] = 230 * scl;
			Ret = ImageKit1.PrintDraw.Polygon(hDC, ref x[0], ref y[0], 3, DeviceMode);

			//Polyline
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.PenColor = RGB(255, 0, 0);
			x[0] = 110 * scl; y[0] = 210 * scl;
			x[1] = 130 * scl; y[1] = 220 * scl;
			x[2] = 120 * scl; y[2] = 230 * scl;
			Ret = ImageKit1.PrintDraw.Polyline(hDC, ref x[0], ref y[0], 3, DeviceMode);

			//TextOut
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.FontName = "Times New Roman";
			ImageKit1.PrintDraw.FontSize = 20;
			ImageKit1.PrintDraw.HCentering = 1;
			ImageKit1.PrintDraw.VCentering = 1;
			ImageKit1.PrintDraw.CharExtra = 10 * scl;
			ImageKit1.PrintDraw.FontItalic = true;
			ImageKit1.PrintDraw.Transparent = true;
			ImageKit1.PrintDraw.Text = "NEWTONE Inc";
			Ret = ImageKit1.PrintDraw.TextOut(hDC, 10, 250, DeviceMode);
			ImageKit1.PrintDraw.CharExtra = 0;
			Ret = ImageKit1.PrintDraw.TextOut(hDC, 10, 270, DeviceMode);

			//Arc
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.PenColor = RGB(0, 255, 0);
			Ret = ImageKit1.PrintDraw.Arc(hDC, 10 * scl, 300 * scl, 100 * scl, 350 * scl, 100 * scl, 320 * scl, 10 * scl, 320 * scl, DeviceMode);

			//Pie
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.PenColor = RGB(0, 255, 255);
			Ret = ImageKit1.PrintDraw.Pie(hDC, 110 * scl, 300 * scl, 200 * scl, 350 * scl, 200 * scl, 320 * scl, 110 * scl, 320 * scl, DeviceMode);

			//Chord
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.PenColor = RGB(64, 128, 255);
			Ret = ImageKit1.PrintDraw.Chord(hDC, 10 * scl, 350 * scl, 100 * scl, 400 * scl, 100 * scl, 370 * scl, 10 * scl, 370 * scl, DeviceMode);

			//RoundRect
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.PenColor = RGB(64, 128, 255);
			Ret = ImageKit1.PrintDraw.RoundRect(hDC, 110 * scl, 350 * scl, 200 * scl, 400 * scl, 30 * scl, 30 * scl, DeviceMode);

			//FillRect
			ImageKit1.PrintDraw.ClearProperty();
			ImageKit1.PrintDraw.PenWidth = 1;
			ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
			ImageKit1.PrintDraw.BrushStyle = IMAGEKIT7Lib.BrushStyleConstants.ikBrushSolid;
			ImageKit1.PrintDraw.BrushColor = RGB(255, 0, 0);
			Ret = ImageKit1.PrintDraw.FillRect(hDC, 250 * scl, 350 * scl, 300 * scl, 400 * scl, DeviceMode);
		}

		private void ImageKit1_EndDispImage(object sender, AxIMAGEKIT7Lib._IImageKitEvents_EndDispImageEvent e)
		{
			Disp(true, (ImageKit1.hDC));
		}

		
		//load image
		private void Command1_Click(object sender, System.EventArgs e)
		{
			if (ImageKit1.File.OpenFileDialog() == false) 
				return;

			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);

			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale);
		}

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

		//set printer
		private void Command2_Click(object sender, System.EventArgs e)
		{
			bool Ret;

			ImageKit1.PrintDraw.PrintFileName = "IkPrn.Ik";
			Ret = ImageKit1.PrintDraw.SavePrinterInfo();
		}

		//print
		private void Command3_Click(object sender, System.EventArgs e)
		{
		
			bool Ret, Ret2;
			//create device context from print file
			ImageKit1.PrintDraw.PrintFileName = "IkPrn.Ik";
			Ret = ImageKit1.PrintDraw.PrintCreateDC(IMAGEKIT7Lib.PrintModeConstants.ikPrintFileName);
			//if print file doesn't exist then set some print properties
			if (Ret == false)
			{
				ImageKit1.PrintDraw.Copies = 1;
				ImageKit1.PrintDraw.Options = 0x04 | 0x08 | 0x100000;
				ImageKit1.PrintDraw.PrintToFile = false;
				Ret2 = ImageKit1.PrintDraw.PrintDialog();
				if (Ret2 == false) return;
			}

			//start printing document and page
			ImageKit1.PrintDraw.DocName = "Print Out";
			Ret = ImageKit1.PrintDraw.PrintStartDoc();
			Ret = ImageKit1.PrintDraw.PrintStartPage();

			//call the Disp function (see below)
			Disp(false, (ImageKit1.PrintDraw.hDC));

			//once the Disp function has executed, end printing page and document
			Ret = ImageKit1.PrintDraw.PrintEndPage();
			Ret = ImageKit1.PrintDraw.PrintEndDoc();

			//delete the device context
			ImageKit1.PrintDraw.PrintDeleteDC();
		}





	
		
		


}
}
