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;

namespace PrimeFactors
{
    public partial class frm86PrimeFactors : Form
    {
        public frm86PrimeFactors()
        {
            InitializeComponent();
        }

        // Find the number's factors.
        private void factorButton_Click(object sender, EventArgs e)
        {
            factorsTextBox.Clear();

            // Get the number.
            long number;
            if (!long.TryParse(numbeTextBox.Text, out number))
            {
                MessageBox.Show("The number must be between 2 and " + long.MaxValue);
                factorsTextBox.Focus();
                return;
            }

            // Get the factors.
            List<long> factors = number.Factor();
            List<string> strings = factors.ConvertAll<string>(x => x.ToString());
            factorsTextBox.Text = string.Join(" x ", strings.ToArray());
        }


        /// <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.factorsTextBox = new System.Windows.Forms.TextBox();
            this.factorButton = new System.Windows.Forms.Button();
            this.numbeTextBox = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // factorsTextBox
            // 
            this.factorsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.factorsTextBox.Location = new System.Drawing.Point(12, 79);
            this.factorsTextBox.Name = "factorsTextBox";
            this.factorsTextBox.ReadOnly = true;
            this.factorsTextBox.Size = new System.Drawing.Size(260, 20);
            this.factorsTextBox.TabIndex = 7;
            this.factorsTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // factorButton
            // 
            this.factorButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
            this.factorButton.Location = new System.Drawing.Point(105, 39);
            this.factorButton.Name = "factorButton";
            this.factorButton.Size = new System.Drawing.Size(75, 23);
            this.factorButton.TabIndex = 6;
            this.factorButton.Text = "Factor";
            this.factorButton.UseVisualStyleBackColor = true;
            this.factorButton.Click += new System.EventHandler(this.factorButton_Click);
            // 
            // numbeTextBox
            // 
            this.numbeTextBox.Anchor = System.Windows.Forms.AnchorStyles.Top;
            this.numbeTextBox.Location = new System.Drawing.Point(65, 13);
            this.numbeTextBox.Name = "numbeTextBox";
            this.numbeTextBox.Size = new System.Drawing.Size(207, 20);
            this.numbeTextBox.TabIndex = 5;
            this.numbeTextBox.Text = "1234567890";
            this.numbeTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // label1
            // 
            this.label1.Anchor = System.Windows.Forms.AnchorStyles.Top;
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 16);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(47, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Number:";
            // 
            // frm86PrimeFactors
            // 
            this.AcceptButton = this.factorButton;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 111);
            this.Controls.Add(this.factorsTextBox);
            this.Controls.Add(this.factorButton);
            this.Controls.Add(this.numbeTextBox);
            this.Controls.Add(this.label1);
            this.Name = "frm86PrimeFactors";
            this.Text = "PrimeFactors";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox factorsTextBox;
        private System.Windows.Forms.Button factorButton;
        private System.Windows.Forms.TextBox numbeTextBox;
        private System.Windows.Forms.Label label1;
    }
}