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 Features
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button closeButton;
        private AxSftBoxLib45.AxSftBox SftBox1;
        private System.Windows.Forms.PictureBox picturePin;
        private System.Windows.Forms.PictureBox pictureSpecial;
        private System.Windows.Forms.PictureBox picturePic;
        private Font BoldFont, ItalicFont;

        /// <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.label1 = new System.Windows.Forms.Label();
            this.closeButton = new System.Windows.Forms.Button();
            this.SftBox1 = new AxSftBoxLib45.AxSftBox();
            this.picturePin = new System.Windows.Forms.PictureBox();
            this.pictureSpecial = new System.Windows.Forms.PictureBox();
            this.picturePic = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.SftBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(7, 8);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(307, 37);
            this.label1.TabIndex = 0;
            this.label1.Text = "This sample shows how bitmaps, colors, fonts and multiple text lines can be used." +
                "";
            // 
            // closeButton
            // 
            this.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.closeButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.closeButton.Location = new System.Drawing.Point(321, 8);
            this.closeButton.Name = "closeButton";
            this.closeButton.Size = new System.Drawing.Size(74, 30);
            this.closeButton.TabIndex = 1;
            this.closeButton.Text = "Close";
            this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
            // 
            // SftBox1
            // 
            this.SftBox1.Location = new System.Drawing.Point(7, 45);
            this.SftBox1.Name = "SftBox1";
            this.SftBox1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("SftBox1.OcxState")));
            this.SftBox1.Size = new System.Drawing.Size(388, 334);
            this.SftBox1.TabIndex = 2;
            // 
            // picturePin
            // 
            this.picturePin.Image = ((System.Drawing.Image)(resources.GetObject("picturePin.Image")));
            this.picturePin.Location = new System.Drawing.Point(227, 379);
            this.picturePin.Name = "picturePin";
            this.picturePin.Size = new System.Drawing.Size(21, 15);
            this.picturePin.TabIndex = 3;
            this.picturePin.TabStop = false;
            this.picturePin.Visible = false;
            // 
            // pictureSpecial
            // 
            this.pictureSpecial.Image = ((System.Drawing.Image)(resources.GetObject("pictureSpecial.Image")));
            this.pictureSpecial.Location = new System.Drawing.Point(263, 379);
            this.pictureSpecial.Name = "pictureSpecial";
            this.pictureSpecial.Size = new System.Drawing.Size(22, 15);
            this.pictureSpecial.TabIndex = 4;
            this.pictureSpecial.TabStop = false;
            this.pictureSpecial.Visible = false;
            // 
            // picturePic
            // 
            this.picturePic.Image = ((System.Drawing.Image)(resources.GetObject("picturePic.Image")));
            this.picturePic.Location = new System.Drawing.Point(300, 379);
            this.picturePic.Name = "picturePic";
            this.picturePic.Size = new System.Drawing.Size(21, 15);
            this.picturePic.TabIndex = 5;
            this.picturePic.TabStop = false;
            this.picturePic.Visible = false;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.closeButton;
            this.ClientSize = new System.Drawing.Size(401, 388);
            this.Controls.Add(this.picturePic);
            this.Controls.Add(this.pictureSpecial);
            this.Controls.Add(this.picturePin);
            this.Controls.Add(this.SftBox1);
            this.Controls.Add(this.closeButton);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.Text = "Softel vdm, Inc. - Features Sample";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.SftBox1)).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 closeButton_Click(object sender, System.EventArgs e)
        {
            Application.Exit();
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            BoldFont = new Font(SftBox1.Font, FontStyle.Bold);
            ItalicFont = new Font("Arial", 8, FontStyle.Italic);

            int index;
            SftBox1.BulkUpdate = true;
            for (index = 0 ; index < 30 ; ++index) {
                if (index == 4)
                    AddOneItem("Item " + index, "This cell text is very long", "Cell " + index + ",2");
                else if (index == 7)
                    AddOneItem("Item " + index, "Cell " + index + ",1", "This cell text is also very long");
                else
                    AddOneItem("Item " + index, "Cell " + index + ",1", "Cell " + index + ",2");
            }
            SftBox1.BulkUpdate = false;
            
            SftBox1.get_Column(0).Width = SftBox1.Width / 4;
            SftBox1.get_Column(1).Width = SftBox1.Width / 4;
            SftBox1.RowHeaders.MakeOptimal(0);
            SftBox1.get_Column(2).MakeOptimal(0);
            SftBox1.Items.RecalcHorizontalExtent(0);
        }

        int AddOneItem(string Cell0, string Cell1, string Cell2)
        {
            int index = SftBox1.Items.Add(Cell0);
            SftBox1.get_Cell(index, 1).Text = Cell1;
            if (index % 4 == 0) {
                SftBox1.get_Cell(index, 1).Image.NETImageObject = pictureSpecial.Image;
                if (index % 8 == 0)
                    SftBox1.get_Cell(index, 1).ImageHAlign = SftBoxHAlignConstants.halignSftBoxRight;
            }
            SftBox1.get_Cell(index, 2).Text = Cell2;
            if (index % 5 == 0) {
                SftBox1.get_Cell(index, 2).Image.NETImageObject = picturePin.Image;
                if (index % 10 == 0)
                    SftBox1.get_Cell(index, 2).ImageHAlign = SftBoxHAlignConstants.halignSftBoxRight;
            }
            if (index % 3 == 0) {
                SftBox1.get_Item(index).RowHeader.Image.NETImageObject = picturePic.Image;
              if (index % 6 == 0)
                  SftBox1.get_Item(index).RowHeader.ImageHAlign = SftBoxHAlignConstants.halignSftBoxRight;
            }
            if (index % 6 == 0) {
                SftBox1.get_Cell(index, 0).Font = OLECvt.ToIFontDisp(BoldFont);
            }
            if (index % 7 == 0) {
                SftBox1.get_Cell(index, 1).Font = OLECvt.ToIFontDisp(ItalicFont);
            }
            return index;
        }
    }

}