using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Globalization;

namespace ChangeBases
{
    public partial class frm87ChangeBases : Form
    {
        public frm87ChangeBases()
        {
            InitializeComponent();
        }

        private void frm87ChangeBases_Load(object sender, EventArgs e)
        {
            decimalTextBox.Text = "1234567890";
        }

        // Get the value from the sender and
        // display it in the other TextBoxes.
        private bool ignoreEvents = false;
        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            // Don't recurse.
            if (ignoreEvents) return;
            ignoreEvents = true;

            // Get the sender as a TextBox.
            TextBox source = sender as TextBox;

            // Get the value.
            long value = 0;
            try
            {
                switch (source.Name)
                {
                    case "decimalTextBox":
                        // Parse a decimal value.
                        value = long.Parse(source.Text);
                        break;
                    case "hexadecimalTextBox":
                        // Parse a hexadecimal value.
                        value = Convert.ToInt64(source.Text, 16);
                        break;
                    case "octalTextBox":
                        // Parse an octal value.
                        value = Convert.ToInt64(source.Text, 8);
                        break;
                    case "binaryTextBox":
                        // Parse a binary value.
                        value = Convert.ToInt64(source.Text, 2);
                        break;
                    default:
                        throw new Exception("Unknown control " + source.Name);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error parsing input\n\n" + ex.Message,
                    "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            // Display the value in different formats.
            if (source.Name != "decimalTextBox")
                decimalTextBox.Text = value.ToString();
            if (source.Name != "hexadecimalTextBox")
                hexadecimalTextBox.Text = Convert.ToString(value, 16);
            if (source.Name != "octalTextBox")
                octalTextBox.Text = Convert.ToString(value, 8);
            if (source.Name != "binaryTextBox")
                binaryTextBox.Text = Convert.ToString(value, 2);

            ignoreEvents = false;
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (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.binaryTextBox = new System.Windows.Forms.TextBox();
            this.octalTextBox = new System.Windows.Forms.TextBox();
            this.hexadecimalTextBox = new System.Windows.Forms.TextBox();
            this.decimalTextBox = new System.Windows.Forms.TextBox();
            this._Label1_3 = new System.Windows.Forms.Label();
            this._Label1_2 = new System.Windows.Forms.Label();
            this._Label1_1 = new System.Windows.Forms.Label();
            this._Label1_0 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // binaryTextBox
            // 
            this.binaryTextBox.AcceptsReturn = true;
            this.binaryTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.binaryTextBox.BackColor = System.Drawing.SystemColors.Window;
            this.binaryTextBox.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.binaryTextBox.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.binaryTextBox.ForeColor = System.Drawing.SystemColors.WindowText;
            this.binaryTextBox.Location = new System.Drawing.Point(91, 91);
            this.binaryTextBox.MaxLength = 0;
            this.binaryTextBox.Name = "binaryTextBox";
            this.binaryTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.binaryTextBox.Size = new System.Drawing.Size(207, 20);
            this.binaryTextBox.TabIndex = 31;
            this.binaryTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.binaryTextBox.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
            // 
            // octalTextBox
            // 
            this.octalTextBox.AcceptsReturn = true;
            this.octalTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.octalTextBox.BackColor = System.Drawing.SystemColors.Window;
            this.octalTextBox.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.octalTextBox.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.octalTextBox.ForeColor = System.Drawing.SystemColors.WindowText;
            this.octalTextBox.Location = new System.Drawing.Point(91, 65);
            this.octalTextBox.MaxLength = 0;
            this.octalTextBox.Name = "octalTextBox";
            this.octalTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.octalTextBox.Size = new System.Drawing.Size(207, 20);
            this.octalTextBox.TabIndex = 30;
            this.octalTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.octalTextBox.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
            // 
            // hexadecimalTextBox
            // 
            this.hexadecimalTextBox.AcceptsReturn = true;
            this.hexadecimalTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.hexadecimalTextBox.BackColor = System.Drawing.SystemColors.Window;
            this.hexadecimalTextBox.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.hexadecimalTextBox.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.hexadecimalTextBox.ForeColor = System.Drawing.SystemColors.WindowText;
            this.hexadecimalTextBox.Location = new System.Drawing.Point(91, 39);
            this.hexadecimalTextBox.MaxLength = 0;
            this.hexadecimalTextBox.Name = "hexadecimalTextBox";
            this.hexadecimalTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.hexadecimalTextBox.Size = new System.Drawing.Size(207, 20);
            this.hexadecimalTextBox.TabIndex = 29;
            this.hexadecimalTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.hexadecimalTextBox.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
            // 
            // decimalTextBox
            // 
            this.decimalTextBox.AcceptsReturn = true;
            this.decimalTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.decimalTextBox.BackColor = System.Drawing.SystemColors.Window;
            this.decimalTextBox.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.decimalTextBox.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.decimalTextBox.ForeColor = System.Drawing.SystemColors.WindowText;
            this.decimalTextBox.Location = new System.Drawing.Point(91, 13);
            this.decimalTextBox.MaxLength = 0;
            this.decimalTextBox.Name = "decimalTextBox";
            this.decimalTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.decimalTextBox.Size = new System.Drawing.Size(207, 20);
            this.decimalTextBox.TabIndex = 28;
            this.decimalTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.decimalTextBox.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
            // 
            // _Label1_3
            // 
            this._Label1_3.BackColor = System.Drawing.SystemColors.Control;
            this._Label1_3.Cursor = System.Windows.Forms.Cursors.Default;
            this._Label1_3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._Label1_3.ForeColor = System.Drawing.SystemColors.ControlText;
            this._Label1_3.Location = new System.Drawing.Point(13, 94);
            this._Label1_3.Name = "_Label1_3";
            this._Label1_3.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this._Label1_3.Size = new System.Drawing.Size(65, 17);
            this._Label1_3.TabIndex = 27;
            this._Label1_3.Text = "Binary:";
            // 
            // _Label1_2
            // 
            this._Label1_2.BackColor = System.Drawing.SystemColors.Control;
            this._Label1_2.Cursor = System.Windows.Forms.Cursors.Default;
            this._Label1_2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._Label1_2.ForeColor = System.Drawing.SystemColors.ControlText;
            this._Label1_2.Location = new System.Drawing.Point(13, 68);
            this._Label1_2.Name = "_Label1_2";
            this._Label1_2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this._Label1_2.Size = new System.Drawing.Size(65, 17);
            this._Label1_2.TabIndex = 26;
            this._Label1_2.Text = "Octal:";
            // 
            // _Label1_1
            // 
            this._Label1_1.BackColor = System.Drawing.SystemColors.Control;
            this._Label1_1.Cursor = System.Windows.Forms.Cursors.Default;
            this._Label1_1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._Label1_1.ForeColor = System.Drawing.SystemColors.ControlText;
            this._Label1_1.Location = new System.Drawing.Point(13, 42);
            this._Label1_1.Name = "_Label1_1";
            this._Label1_1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this._Label1_1.Size = new System.Drawing.Size(72, 17);
            this._Label1_1.TabIndex = 25;
            this._Label1_1.Text = "Hexadecimal:";
            // 
            // _Label1_0
            // 
            this._Label1_0.BackColor = System.Drawing.SystemColors.Control;
            this._Label1_0.Cursor = System.Windows.Forms.Cursors.Default;
            this._Label1_0.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._Label1_0.ForeColor = System.Drawing.SystemColors.ControlText;
            this._Label1_0.Location = new System.Drawing.Point(13, 16);
            this._Label1_0.Name = "_Label1_0";
            this._Label1_0.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this._Label1_0.Size = new System.Drawing.Size(65, 17);
            this._Label1_0.TabIndex = 24;
            this._Label1_0.Text = "Decimal:";
            // 
            // frm87ChangeBases
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(311, 124);
            this.Controls.Add(this.binaryTextBox);
            this.Controls.Add(this.octalTextBox);
            this.Controls.Add(this.hexadecimalTextBox);
            this.Controls.Add(this.decimalTextBox);
            this.Controls.Add(this._Label1_3);
            this.Controls.Add(this._Label1_2);
            this.Controls.Add(this._Label1_1);
            this.Controls.Add(this._Label1_0);
            this.Name = "frm87ChangeBases";
            this.Text = "ChangeBases";
            this.Load += new System.EventHandler(this.frm87ChangeBases_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        public System.Windows.Forms.TextBox binaryTextBox;
        public System.Windows.Forms.TextBox octalTextBox;
        public System.Windows.Forms.TextBox hexadecimalTextBox;
        public System.Windows.Forms.TextBox decimalTextBox;
        public System.Windows.Forms.Label _Label1_3;
        public System.Windows.Forms.Label _Label1_2;
        public System.Windows.Forms.Label _Label1_1;
        public System.Windows.Forms.Label _Label1_0;
    }
}