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

using SftBoxLib45;
using AxSftBoxLib45;
using Softelvdm.OLEConvert;

namespace Pictures
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        public System.Windows.Forms.MenuItem AppExit;
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.ImageList imageList1;
        public System.Windows.Forms.MenuItem menuItem1;
        internal System.Windows.Forms.Button Button1;
        public System.Windows.Forms.PictureBox PictureIcon;
        public System.Windows.Forms.PictureBox PictureLogo;
        internal System.Windows.Forms.ImageList imageList2;
        internal System.Windows.Forms.MainMenu mainMenu2;
        public System.Windows.Forms.Label Label2;
        public System.Windows.Forms.PictureBox PictureSmallBitmap;
        public System.Windows.Forms.PictureBox PictureIconSmall;
        private AxSftBoxLib45.AxSftBox axSftBox1;
        private System.Windows.Forms.PictureBox picturePNG2;
        private System.Windows.Forms.PictureBox picturePNG1;

        private bool m_SortDirection;

        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.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.AppExit = new System.Windows.Forms.MenuItem();
            this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.Button1 = new System.Windows.Forms.Button();
            this.axSftBox1 = new AxSftBoxLib45.AxSftBox();
            this.PictureIcon = new System.Windows.Forms.PictureBox();
            this.PictureLogo = new System.Windows.Forms.PictureBox();
            this.imageList2 = new System.Windows.Forms.ImageList(this.components);
            this.mainMenu2 = new System.Windows.Forms.MainMenu(this.components);
            this.Label2 = new System.Windows.Forms.Label();
            this.PictureSmallBitmap = new System.Windows.Forms.PictureBox();
            this.PictureIconSmall = new System.Windows.Forms.PictureBox();
            this.picturePNG2 = new System.Windows.Forms.PictureBox();
            this.picturePNG1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.axSftBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureIcon)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureLogo)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureSmallBitmap)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureIconSmall)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.picturePNG2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.picturePNG1)).BeginInit();
            this.SuspendLayout();
            // 
            // AppExit
            // 
            this.AppExit.Index = -1;
            this.AppExit.Text = "E&xit";
            // 
            // imageList1
            // 
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.DarkGray;
            this.imageList1.Images.SetKeyName(0, "");
            this.imageList1.Images.SetKeyName(1, "");
            this.imageList1.Images.SetKeyName(2, "");
            this.imageList1.Images.SetKeyName(3, "");
            this.imageList1.Images.SetKeyName(4, "");
            this.imageList1.Images.SetKeyName(5, "");
            this.imageList1.Images.SetKeyName(6, "");
            this.imageList1.Images.SetKeyName(7, "");
            this.imageList1.Images.SetKeyName(8, "");
            this.imageList1.Images.SetKeyName(9, "");
            // 
            // menuItem1
            // 
            this.menuItem1.Index = -1;
            this.menuItem1.Text = "E&xit";
            // 
            // Button1
            // 
            this.Button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Button1.Location = new System.Drawing.Point(480, 8);
            this.Button1.Name = "Button1";
            this.Button1.Size = new System.Drawing.Size(72, 24);
            this.Button1.TabIndex = 19;
            this.Button1.Text = "Close";
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            // 
            // axSftBox1
            // 
            this.axSftBox1.Location = new System.Drawing.Point(16, 16);
            this.axSftBox1.Name = "axSftBox1";
            this.axSftBox1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axSftBox1.OcxState")));
            this.axSftBox1.Size = new System.Drawing.Size(344, 45);
            this.axSftBox1.TabIndex = 0;
            this.axSftBox1.ItemDblClk += new AxSftBoxLib45._ISftBoxEvents_ItemDblClkEventHandler(this.axSftBox1_ItemDblClk);
            this.axSftBox1.ItemClick += new AxSftBoxLib45._ISftBoxEvents_ItemClickEventHandler(this.axSftBox1_ItemClick);
            this.axSftBox1.SelectionChange += new System.EventHandler(this.axSftBox1_SelectionChange);
            // 
            // PictureIcon
            // 
            this.PictureIcon.BackColor = System.Drawing.SystemColors.Control;
            this.PictureIcon.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PictureIcon.Cursor = System.Windows.Forms.Cursors.Default;
            this.PictureIcon.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.PictureIcon.ForeColor = System.Drawing.SystemColors.ControlText;
            this.PictureIcon.Image = ((System.Drawing.Image)(resources.GetObject("PictureIcon.Image")));
            this.PictureIcon.Location = new System.Drawing.Point(424, 104);
            this.PictureIcon.Name = "PictureIcon";
            this.PictureIcon.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.PictureIcon.Size = new System.Drawing.Size(41, 41);
            this.PictureIcon.TabIndex = 23;
            this.PictureIcon.TabStop = false;
            this.PictureIcon.Visible = false;
            // 
            // PictureLogo
            // 
            this.PictureLogo.BackColor = System.Drawing.SystemColors.Control;
            this.PictureLogo.Cursor = System.Windows.Forms.Cursors.Default;
            this.PictureLogo.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.PictureLogo.ForeColor = System.Drawing.SystemColors.ControlText;
            this.PictureLogo.Image = ((System.Drawing.Image)(resources.GetObject("PictureLogo.Image")));
            this.PictureLogo.Location = new System.Drawing.Point(24, 128);
            this.PictureLogo.Name = "PictureLogo";
            this.PictureLogo.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.PictureLogo.Size = new System.Drawing.Size(265, 65);
            this.PictureLogo.TabIndex = 21;
            this.PictureLogo.TabStop = false;
            this.PictureLogo.Visible = false;
            // 
            // imageList2
            // 
            this.imageList2.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList2.ImageStream")));
            this.imageList2.TransparentColor = System.Drawing.Color.DarkGray;
            this.imageList2.Images.SetKeyName(0, "");
            this.imageList2.Images.SetKeyName(1, "");
            this.imageList2.Images.SetKeyName(2, "");
            this.imageList2.Images.SetKeyName(3, "");
            this.imageList2.Images.SetKeyName(4, "");
            this.imageList2.Images.SetKeyName(5, "");
            this.imageList2.Images.SetKeyName(6, "");
            this.imageList2.Images.SetKeyName(7, "");
            this.imageList2.Images.SetKeyName(8, "");
            this.imageList2.Images.SetKeyName(9, "");
            // 
            // Label2
            // 
            this.Label2.BackColor = System.Drawing.SystemColors.Control;
            this.Label2.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label2.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label2.Location = new System.Drawing.Point(24, 208);
            this.Label2.Name = "Label2";
            this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label2.Size = new System.Drawing.Size(513, 49);
            this.Label2.TabIndex = 20;
            this.Label2.Text = "Click on the SftBox/OCX control above and hit F1 to access help information for S" +
                "ftBox/OCX 4.5";
            this.Label2.Visible = false;
            // 
            // PictureSmallBitmap
            // 
            this.PictureSmallBitmap.BackColor = System.Drawing.SystemColors.Control;
            this.PictureSmallBitmap.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PictureSmallBitmap.Cursor = System.Windows.Forms.Cursors.Default;
            this.PictureSmallBitmap.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.PictureSmallBitmap.ForeColor = System.Drawing.SystemColors.ControlText;
            this.PictureSmallBitmap.Image = ((System.Drawing.Image)(resources.GetObject("PictureSmallBitmap.Image")));
            this.PictureSmallBitmap.Location = new System.Drawing.Point(424, 56);
            this.PictureSmallBitmap.Name = "PictureSmallBitmap";
            this.PictureSmallBitmap.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.PictureSmallBitmap.Size = new System.Drawing.Size(41, 41);
            this.PictureSmallBitmap.TabIndex = 22;
            this.PictureSmallBitmap.TabStop = false;
            this.PictureSmallBitmap.Visible = false;
            // 
            // PictureIconSmall
            // 
            this.PictureIconSmall.BackColor = System.Drawing.SystemColors.Control;
            this.PictureIconSmall.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PictureIconSmall.Cursor = System.Windows.Forms.Cursors.Default;
            this.PictureIconSmall.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.PictureIconSmall.ForeColor = System.Drawing.SystemColors.ControlText;
            this.PictureIconSmall.Image = ((System.Drawing.Image)(resources.GetObject("PictureIconSmall.Image")));
            this.PictureIconSmall.Location = new System.Drawing.Point(424, 152);
            this.PictureIconSmall.Name = "PictureIconSmall";
            this.PictureIconSmall.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.PictureIconSmall.Size = new System.Drawing.Size(41, 41);
            this.PictureIconSmall.TabIndex = 24;
            this.PictureIconSmall.TabStop = false;
            this.PictureIconSmall.Visible = false;
            // 
            // picturePNG2
            // 
            this.picturePNG2.Enabled = false;
            this.picturePNG2.Image = ((System.Drawing.Image)(resources.GetObject("picturePNG2.Image")));
            this.picturePNG2.Location = new System.Drawing.Point(480, 128);
            this.picturePNG2.Name = "picturePNG2";
            this.picturePNG2.Size = new System.Drawing.Size(48, 64);
            this.picturePNG2.TabIndex = 26;
            this.picturePNG2.TabStop = false;
            this.picturePNG2.Visible = false;
            // 
            // picturePNG1
            // 
            this.picturePNG1.Enabled = false;
            this.picturePNG1.Image = ((System.Drawing.Image)(resources.GetObject("picturePNG1.Image")));
            this.picturePNG1.Location = new System.Drawing.Point(480, 80);
            this.picturePNG1.Name = "picturePNG1";
            this.picturePNG1.Size = new System.Drawing.Size(40, 40);
            this.picturePNG1.TabIndex = 25;
            this.picturePNG1.TabStop = false;
            this.picturePNG1.Visible = false;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(562, 278);
            this.Controls.Add(this.picturePNG2);
            this.Controls.Add(this.picturePNG1);
            this.Controls.Add(this.PictureIcon);
            this.Controls.Add(this.PictureLogo);
            this.Controls.Add(this.Label2);
            this.Controls.Add(this.PictureSmallBitmap);
            this.Controls.Add(this.PictureIconSmall);
            this.Controls.Add(this.Button1);
            this.Controls.Add(this.axSftBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Menu = this.mainMenu1;
            this.Name = "Form1";
            this.Text = "Softel vdm, Inc. - Pictures Sample";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.axSftBox1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureIcon)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureLogo)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureSmallBitmap)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PictureIconSmall)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.picturePNG2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.picturePNG1)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

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

        private void Button1_Click(object sender, System.EventArgs e)
        {
            Application.Exit();
        }

        private void CopyImageFromCurrentItem()
        {
            int ItemIndex;
            SftPictureObject Img;

            ItemIndex = axSftBox1.Items.Selection;
            if (ItemIndex < 0)
                return;

            // don't use images that are too large in the other areas
            Img = axSftBox1.get_Cell(ItemIndex, 0).Image;
            if (Img.ActualHeight <= 20 && Img.ActualWidth <= 20) {
                axSftBox1.RowColumnHeader.Image = Img;
                axSftBox1.get_Header(1).Image = Img;
            } else {
                axSftBox1.RowColumnHeader.Image.Clear();
                axSftBox1.get_Header(1).Image.Clear();
            }
        }

        private void ToggleImage(SftPictureObject Img)
        {
            switch (Img.Appearance) {
            case SftPictureImageConstants.sftImageCheckboxNo:
                Img.Appearance = SftPictureImageConstants.sftImageCheckboxYes;
                break;
            case SftPictureImageConstants.sftImageCheckboxYes:
                Img.Appearance = SftPictureImageConstants.sftImageCheckboxNo;
                break;
            case SftPictureImageConstants.sftImageCheckboxUnknown:
                Img.Appearance = SftPictureImageConstants.sftImageCheckboxNo;
                break;
            case SftPictureImageConstants.sftImageCheckboxNoDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageCheckboxYesDisabled;
                break;
            case SftPictureImageConstants.sftImageCheckboxYesDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageCheckboxNoDisabled;
                break;
            case SftPictureImageConstants.sftImageCheckboxUnknownDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageCheckboxNoDisabled;
                break;
            case SftPictureImageConstants.sftImageRadioButtonNo:
                Img.Appearance = SftPictureImageConstants.sftImageRadioButtonYes;
                break;
            case SftPictureImageConstants.sftImageRadioButtonYes:
                Img.Appearance = SftPictureImageConstants.sftImageRadioButtonNo;
                break;
            case SftPictureImageConstants.sftImageRadioButtonNoDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageRadioButtonYesDisabled;
                break;
            case SftPictureImageConstants.sftImageRadioButtonYesDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageRadioButtonNoDisabled;
                break;
            case SftPictureImageConstants.sftImageUp:
                Img.Appearance = SftPictureImageConstants.sftImageDown;
                break;
            case SftPictureImageConstants.sftImageUpDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageDownDisabled;
                break;
            case SftPictureImageConstants.sftImageDown:
                Img.Appearance = SftPictureImageConstants.sftImageUp;
                break;
            case SftPictureImageConstants.sftImageDownDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageUpDisabled;
                break;
            case SftPictureImageConstants.sftImageSortAsc:
                Img.Appearance = SftPictureImageConstants.sftImageSortDesc;
                break;
            case SftPictureImageConstants.sftImageSortAscDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageSortDescDisabled;
                break;
            case SftPictureImageConstants.sftImageSortDesc:
                Img.Appearance = SftPictureImageConstants.sftImageSortAsc;
                break;
            case SftPictureImageConstants.sftImageSortDescDisabled:
                Img.Appearance = SftPictureImageConstants.sftImageSortAscDisabled;
                break;
            }
        }

        private void PropagateImage(int ItemIndex, SftPictureObject Img)
        {
            // don't use images that are too large in the other areas
            if (Img.ActualHeight <= 20 && Img.ActualWidth < 20) {
                axSftBox1.get_Item(ItemIndex).Image = Img;
                axSftBox1.get_Item(ItemIndex).LabelImage = Img;
                axSftBox1.get_Item(ItemIndex).RowHeader.Image = Img;
            }
        }

        private void UpdateImages(int ItemIndex, System.Drawing.Image img, SftBoxHAlignConstants Align)
        {
            SftBoxCell C = axSftBox1.get_Cell(ItemIndex, 0);
            C.Image.NETImageObject = img;
            C.ImageHAlign = Align;
            PropagateImage(ItemIndex, C.Image);
        }

        private void UpdateImageList(int ItemIndex, ImageList ImageListControl, int i, SftBoxHAlignConstants Align)
        {
            SftBoxCell C = axSftBox1.get_Cell(ItemIndex, 0);
            C.Image.SetImageListH((int) ImageListControl.Handle, (short) i);
            C.ImageHAlign = Align;
            PropagateImage(ItemIndex, C.Image);
        }

        private void UpdateColor(int ItemIndex, System.Drawing.Color Clr, SftBoxHAlignConstants Align)
        {
            SftBoxCell C = axSftBox1.get_Cell(ItemIndex, 0);
            C.Image.SetColorSample(OLECvt.ToOleColor(Clr), OLECvt.ToOleColor(Color.Black));
            C.Image.Width = 12;
            C.Image.Height = 12;
            C.ImageHAlign = Align;
            PropagateImage(ItemIndex, C.Image);
        }

        private void AddColor(string Text, Color Clr)
        {
            int i;
            i = axSftBox1.Items.Add(Text);
            axSftBox1.get_Item(i).Level = 2;
            UpdateColor(i, Clr, SftBoxHAlignConstants.halignSftBoxRight);
        }

        private void UpdateBuiltinImage(int ItemIndex, SftPictureImageConstants Style, int wPix, int hPix, SftBoxHAlignConstants Align)
        {
            SftBoxCell C = axSftBox1.get_Cell(ItemIndex, 0);
            C.Image.Appearance = Style;
            C.Image.Width = wPix;
            C.Image.Height = hPix;
            C.ImageHAlign = Align;
            PropagateImage(ItemIndex, C.Image);
        }

        private void AddBuiltinImage(string Text, SftPictureImageConstants Style, int wPix, int hPix)
        {
            int i = axSftBox1.Items.Add(Text);
            axSftBox1.get_Item(i).Level = 2;
            UpdateBuiltinImage(i, Style, wPix, hPix, SftBoxHAlignConstants.halignSftBoxRight);
        }

        private void ShowSortDirection(bool Ascending)
        {
            if (Ascending)
                axSftBox1.get_Header(0).Image.Appearance = SftPictureImageConstants.sftImageSortAsc;
            else
                axSftBox1.get_Header(0).Image.Appearance = SftPictureImageConstants.sftImageSortDesc;
            m_SortDirection = Ascending;
        }

        private void SetSortDirection(bool NewDirection)
        {
            ShowSortDirection(NewDirection);
            if (NewDirection)
                axSftBox1.Items.Sort(-1, 0, SftBoxSortConstants.sortSftBoxAscending);
            else
                axSftBox1.Items.Sort(-1, 0, SftBoxSortConstants.sortSftBoxDescending);
        }

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

            int ItemIndex = axSftBox1.Items.Add("Supported Picture Types");
            axSftBox1.get_Cell(ItemIndex, 1).Text = "SftBox/OCX supports numerous image types, such as GDI+ images, bitmaps, icons, ImageLists and also offers numerous built-in images.";

            // add GDI+ samples

            ItemIndex = axSftBox1.Items.Add("GDI+ Images");
            axSftBox1.get_Item(ItemIndex).Level = 1;
            axSftBox1.get_Cell(ItemIndex, 1).Text = "All GDI+ images are supported, like GIF, JPEG, Exif, PNG, TIFF and device-independent bitmaps (up to 64bpp) with semi-transparent and translucent areas.";

            int I = axSftBox1.Items.Add("PNG Sample with alpha-channel for translucent edges");
            axSftBox1.get_Item(I).Level = 2;
            UpdateImages(I, picturePNG1.Image, SftBoxHAlignConstants.halignSftBoxRight);

            I = axSftBox1.Items.Add("Another PNG Sample with alpha-channel for translucent edges");
            axSftBox1.get_Item(I).Level = 2;
            UpdateImages(I, picturePNG2.Image, SftBoxHAlignConstants.halignSftBoxRight);

            // add bitmap samples

            ItemIndex = axSftBox1.Items.Add("Bitmaps");
            axSftBox1.get_Item(ItemIndex).Level = 1;
            axSftBox1.get_Cell(ItemIndex, 1).Text = "Bitmaps can be of varying sizes and also support Bitmap Transparency, which allows the background to show through the image (in areas selected by the bitmap designer).";

            I = axSftBox1.Items.Add("Large Bitmap");
            axSftBox1.get_Item(I).Level = 2;
            UpdateImages(I, PictureLogo.Image, SftBoxHAlignConstants.halignSftBoxRight);

            I = axSftBox1.Items.Add("Various bitmap sizes");
            axSftBox1.get_Item(I).Level = 2;
            UpdateImages(I, PictureSmallBitmap.Image, SftBoxHAlignConstants.halignSftBoxRight);

            // add icon samples

            ItemIndex = axSftBox1.Items.Add("Icons");
            axSftBox1.get_Item(ItemIndex).Level = 1;
            axSftBox1.get_Cell(ItemIndex, 1).Text = "The supported icons can be stardard size icons (32x32) or any other size supported by the operating system.";

            I = axSftBox1.Items.Add("Standard Icon (32x32)");
            axSftBox1.get_Item(I).Level = 2;
            UpdateImages(I, PictureIcon.Image, SftBoxHAlignConstants.halignSftBoxRight);

            I = axSftBox1.Items.Add("Any other size");
            axSftBox1.get_Item(I).Level = 2;
            UpdateImages(I, PictureIconSmall.Image, SftBoxHAlignConstants.halignSftBoxRight);

            // add imagelist samples

            ItemIndex = axSftBox1.Items.Add("ImageLists");
            axSftBox1.get_Item(ItemIndex).Level = 1;
            axSftBox1.get_Cell(ItemIndex, 1).Text = "Complete ImageList support simplifies bitmap handling and can avoid the limited resource availability on earlier Windows versions.";

            for (int C = 0 ; C < imageList1.Images.Count ; ++C) {
                I = axSftBox1.Items.Add("Image " + C.ToString());
                axSftBox1.get_Item(I).Level = 2;
                UpdateImageList(I, imageList1, C, SftBoxHAlignConstants.halignSftBoxRight);
            }

            // add color samples

            ItemIndex = axSftBox1.Items.Add("Color Samples");
            axSftBox1.get_Item(ItemIndex).Level = 1;
            axSftBox1.get_Cell(ItemIndex, 1).Text = "Using the built-in color sample image, simple color selection can easily be implemented.  Color samples can display all colors available.";

            AddColor("Black", System.Drawing.Color.Black);
            AddColor("Blue", System.Drawing.Color.Blue);
            AddColor("Cyan", System.Drawing.Color.Cyan);
            AddColor("Green", System.Drawing.Color.Lime);
            AddColor("Magenta", System.Drawing.Color.Magenta);
            AddColor("Red", System.Drawing.Color.Red);
            AddColor("White", System.Drawing.Color.White);
            AddColor("Yellow", System.Drawing.Color.Yellow);

            AddColor("3DDKSHADOW - Dark shadow for 3D elements", System.Drawing.SystemColors.ControlDarkDark);
            AddColor("3DFACE - Face color for 3D elements", System.Drawing.SystemColors.Control);
            AddColor("3DHILIGHT - Edges facing the light source", System.Drawing.SystemColors.ControlLightLight);
            AddColor("3DLIGHT - Edges facing the light source", System.Drawing.SystemColors.ControlLight);
            AddColor("3DSHADOW - Edges facing away from the light source", System.Drawing.SystemColors.ControlDark);
            AddColor("INFOBK - Background color for tooltip controls", System.Drawing.SystemColors.Info);
            AddColor("INFOTEXT - Text color for tooltip controls", System.Drawing.SystemColors.InfoText);
            AddColor("MENUTEXT - Text in menus", System.Drawing.SystemColors.MenuText);
            AddColor("ACTIVEBORDER - Active window border", System.Drawing.SystemColors.ActiveBorder);
            AddColor("ACTIVECAPTION - Active window caption", System.Drawing.SystemColors.ActiveCaption);
            AddColor("APPWORKSPACE - Background color MDI applications", System.Drawing.SystemColors.AppWorkspace);
            AddColor("BACKGROUND - Desktop", System.Drawing.SystemColors.Desktop);
            AddColor("BTNFACE - Face shading on push buttons", System.Drawing.SystemColors.Control);
            AddColor("BTNHILIGHT - Highlight color for buttons", System.Drawing.SystemColors.ControlLightLight);
            AddColor("BTNSHADOW - Edge shading on push buttons", System.Drawing.SystemColors.ControlDark);
            AddColor("BTNTEXT - Text on push buttons", System.Drawing.SystemColors.ControlText);
            AddColor("CAPTIONTEXT - Text in caption", System.Drawing.SystemColors.ActiveCaptionText);
            AddColor("GRAYTEXT - Grayed (disabled); text", System.Drawing.SystemColors.GrayText);
            AddColor("HIGHLIGHT - zystem.Drawing.SystemColors.Highlight);
            AddColor("HIGHLIGHTTEXT - Text of selected item(s)", System.Drawing.SystemColors.HighlightText);
            AddColor("INACTIVEBORDER - Inactive window border", System.Drawing.SystemColors.InactiveBorder);
            AddColor("INACTIVECAPTION - Inactive window caption", System.Drawing.SystemColors.InactiveCaption);
            AddColor("INACTIVECAPTIONTEXT - Inactive caption text color", System.Drawing.SystemColors.InactiveCaptionText);
            AddColor("MENU - Menu background", System.Drawing.SystemColors.Menu);
            AddColor("SCROLLBAR - Scroll bar gray area", System.Drawing.SystemColors.ScrollBar);
            AddColor("WINDOW - Window background", System.Drawing.SystemColors.Window);
            AddColor("WINDOWFRAME - Window frame", System.Drawing.SystemColors.WindowFrame);
            AddColor("WINDOWTEXT - Text in windows", System.Drawing.SystemColors.WindowText);

            // add predefined image samples

            ItemIndex = axSftBox1.Items.Add("Predefined (Built-in) Pictures");
            axSftBox1.get_Cell(ItemIndex, 1).Text = "Predefined images are available for commonly used items, such as check boxes, radio buttons, sort direction indicators and more...";

            ItemIndex = axSftBox1.Items.Add("Check Boxes - Honors Windows Themes");
            axSftBox1.get_Item(ItemIndex).Level = 1;

            AddBuiltinImage("Enabled, Selected Check Box", SftPictureImageConstants.sftImageCheckboxYes, 14, 14);
            AddBuiltinImage("Disabled, Selected Check Box", SftPictureImageConstants.sftImageCheckboxYesDisabled, 14, 14);
            AddBuiltinImage("Enabled Check Box", SftPictureImageConstants.sftImageCheckboxNo, 14, 14);
            AddBuiltinImage("Disabled Check Box", SftPictureImageConstants.sftImageCheckboxNoDisabled, 14, 14);
            AddBuiltinImage("Enabled, Unknown Check Box", SftPictureImageConstants.sftImageCheckboxUnknown, 14, 14);
            AddBuiltinImage("Disabled, Unknown Check Box", SftPictureImageConstants.sftImageCheckboxUnknownDisabled, 14, 14);

            ItemIndex = axSftBox1.Items.Add("Radio Buttons - Honors Windows Themes");
            axSftBox1.get_Item(ItemIndex).Level = 1;

            AddBuiltinImage("Enabled, Selected Radio Button", SftPictureImageConstants.sftImageRadioButtonYes, 14, 14);
            AddBuiltinImage("Disabled, Selected Radio Button", SftPictureImageConstants.sftImageRadioButtonYesDisabled, 14, 14);
            AddBuiltinImage("Enabled Radio Button", SftPictureImageConstants.sftImageRadioButtonNo, 14, 14);
            AddBuiltinImage("Disabled Radio Button", SftPictureImageConstants.sftImageRadioButtonNoDisabled, 14, 14);

            ItemIndex = axSftBox1.Items.Add("Up/Down Buttons - Honors Windows Themes");
            axSftBox1.get_Item(ItemIndex).Level = 1;

            AddBuiltinImage("Enabled Up Button", SftPictureImageConstants.sftImageUp, 14, 14);
            AddBuiltinImage("Disabled Up Button", SftPictureImageConstants.sftImageUpDisabled, 14, 14);
            AddBuiltinImage("Enabled Down Button", SftPictureImageConstants.sftImageDown, 14, 14);
            AddBuiltinImage("Disabled Down Button", SftPictureImageConstants.sftImageDownDisabled, 14, 14);

            ItemIndex = axSftBox1.Items.Add("Sort Direction Indicator");
            axSftBox1.get_Item(ItemIndex).Level = 1;

            AddBuiltinImage("Enabled Ascending Indicator", SftPictureImageConstants.sftImageSortAsc, 8, 8);
            AddBuiltinImage("Disabled Ascending Indicator", SftPictureImageConstants.sftImageSortAscDisabled, 8, 8);
            AddBuiltinImage("Enabled Descending Indicator", SftPictureImageConstants.sftImageSortDesc, 8, 8);
            AddBuiltinImage("Disabled Descending Indicator", SftPictureImageConstants.sftImageSortDescDisabled, 8, 8);


            axSftBox1.RowHeaders.MakeOptimal(0); // make the row headers optimal
            axSftBox1.get_Column(0).MakeOptimal(0); // make the first column optimal
            axSftBox1.Items.RecalcHorizontalExtent(0); // update horizontal scroll bar

            axSftBox1.Items.Selection = 0;

            CopyImageFromCurrentItem();
        }

        private void ExpandCollapseItem(int ItemIndex, short Shift)
        {
            SftBoxItem Item = axSftBox1.get_Item(ItemIndex);
            if (Item.Expanded)
                Item.Collapse(true);
            else
                Item.Expand(true, ((Shift & (short)SftBoxKeyConstants.constSftBoxCtrlMask))!=0 ? true : false);
        }
                
        private void axSftBox1_ItemClick(object sender, AxSftBoxLib45._ISftBoxEvents_ItemClickEvent e)
        {
            switch (e.areaType) {
            case SftBoxAreaConstants.areaSftBoxColumn:
                if (e.colNum == 0)
                    SetSortDirection(!m_SortDirection);
                break;
            case SftBoxAreaConstants.areaSftBoxCellGraphic:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                ToggleImage(axSftBox1.get_Cell(e.itemIndex, e.colNum).Image);
                break;
            case SftBoxAreaConstants.areaSftBoxItem:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                ToggleImage(axSftBox1.get_Item(e.itemIndex).Image);
                break;
            case SftBoxAreaConstants.areaSftBoxLabel:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                ToggleImage(axSftBox1.get_Item(e.itemIndex).LabelImage);
                break;
            case SftBoxAreaConstants.areaSftBoxButton:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                ExpandCollapseItem(e.itemIndex, e.shift);
                break;
            }
        }

        private void axSftBox1_ItemDblClk(object sender, AxSftBoxLib45._ISftBoxEvents_ItemDblClkEvent e)
        {
            switch (e.areaType) {
            case SftBoxAreaConstants.areaSftBoxColumnRes:
                axSftBox1.get_Column(e.colNum).MakeOptimal(0); // Make column width optimal
                axSftBox1.Items.RecalcHorizontalExtent(0); // Update horizontal scroll bar
                break;
            case SftBoxAreaConstants.areaSftBoxColumn:
                if (e.colNum == 0)
                    SetSortDirection(!m_SortDirection);
                break;
            case SftBoxAreaConstants.areaSftBoxCellGraphic:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                ToggleImage(axSftBox1.get_Cell(e.itemIndex, e.colNum).Image);
                break;
            case SftBoxAreaConstants.areaSftBoxLabel:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                ToggleImage(axSftBox1.get_Item(e.itemIndex).LabelImage);
                break;
            case SftBoxAreaConstants.areaSftBoxItem:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                if (axSftBox1.get_Item(e.itemIndex).Expandable)
                    ExpandCollapseItem(e.itemIndex, e.shift);
                else
                    ToggleImage(axSftBox1.get_Item(e.itemIndex).Image);
                break;
            case SftBoxAreaConstants.areaSftBoxButton:
            case SftBoxAreaConstants.areaSftBoxCell:
                if (e.part == SftBoxPortionConstants.partSftBoxDropDown)
                    axSftBox1.DropDown.Suppress(); // Make sure we don't close the drop down
                ExpandCollapseItem(e.itemIndex, e.shift);
                break;
            }
        }

        private void axSftBox1_SelectionChange(object sender, System.EventArgs e)
        {
            CopyImageFromCurrentItem();
        }

    }
}