抵抗のカラーコードを求めるアプリを作ってみた

<img width="372" alt="teitei.png" src="https://qiita-image-store.s3.amazonaws.com/0/33329/309c900e-cf30-f18b-aeb8-7749d0dc596d.png">

数字をテキストボックスに入力するだけでカラーコードが求められます．


```Form1.Designer.cs

namespace Teikou
{
    partial class Form1
    {
        /// <summary>
        /// 必要なデザイナー変数です。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 使用中のリソースをすべてクリーンアップします。
        /// </summary>
        /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows フォーム デザイナーで生成されたコード

        /// <summary>
        /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
        /// コード エディターで変更しないでください。
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.label1 = new System.Windows.Forms.Label();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.label2 = new System.Windows.Forms.Label();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.pictureBox2 = new System.Windows.Forms.PictureBox();
            this.pictureBox3 = new System.Windows.Forms.PictureBox();
            this.pictureBox4 = new System.Windows.Forms.PictureBox();
            this.pictureBox5 = new System.Windows.Forms.PictureBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.pictureBox6 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(40, 27);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(29, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "抵抗";
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = global::Teikou.Properties.Resources.teikou1;
            this.pictureBox1.Location = new System.Drawing.Point(42, 116);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(260, 76);
            this.pictureBox1.TabIndex = 2;
            this.pictureBox1.TabStop = false;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(148, 46);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(17, 12);
            this.label2.TabIndex = 3;
            this.label2.Text = "Ω";
            // 
            // imageList1
            // 
            this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // pictureBox2
            // 
            this.pictureBox2.BackColor = System.Drawing.SystemColors.ControlLightLight;
            this.pictureBox2.Location = new System.Drawing.Point(110, 116);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new System.Drawing.Size(19, 66);
            this.pictureBox2.TabIndex = 4;
            this.pictureBox2.TabStop = false;
            // 
            // pictureBox3
            // 
            this.pictureBox3.Location = new System.Drawing.Point(137, 116);
            this.pictureBox3.Name = "pictureBox3";
            this.pictureBox3.Size = new System.Drawing.Size(19, 66);
            this.pictureBox3.TabIndex = 5;
            this.pictureBox3.TabStop = false;
            // 
            // pictureBox4
            // 
            this.pictureBox4.Location = new System.Drawing.Point(162, 116);
            this.pictureBox4.Name = "pictureBox4";
            this.pictureBox4.Size = new System.Drawing.Size(19, 66);
            this.pictureBox4.TabIndex = 6;
            this.pictureBox4.TabStop = false;
            // 
            // pictureBox5
            // 
            this.pictureBox5.BackColor = System.Drawing.Color.Maroon;
            this.pictureBox5.Location = new System.Drawing.Point(197, 116);
            this.pictureBox5.Name = "pictureBox5";
            this.pictureBox5.Size = new System.Drawing.Size(12, 66);
            this.pictureBox5.TabIndex = 7;
            this.pictureBox5.TabStop = false;
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(42, 43);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 19);
            this.textBox1.TabIndex = 8;
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(42, 226);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 9;
            this.button1.Text = "決定";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // pictureBox6
            // 
            this.pictureBox6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
            this.pictureBox6.Location = new System.Drawing.Point(215, 116);
            this.pictureBox6.Name = "pictureBox6";
            this.pictureBox6.Size = new System.Drawing.Size(12, 66);
            this.pictureBox6.TabIndex = 10;
            this.pictureBox6.TabStop = false;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(377, 261);
            this.Controls.Add(this.pictureBox6);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.pictureBox5);
            this.Controls.Add(this.pictureBox4);
            this.Controls.Add(this.pictureBox3);
            this.Controls.Add(this.pictureBox2);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.label1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.ImageList imageList1;
        private System.Windows.Forms.PictureBox pictureBox2;
        private System.Windows.Forms.PictureBox pictureBox3;
        private System.Windows.Forms.PictureBox pictureBox4;
        private System.Windows.Forms.PictureBox pictureBox5;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.PictureBox pictureBox6;
    }
}

```


```Form1.cs

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 Teikou
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
         
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
                char[] c = textBox1.Text.ToCharArray();
                int color = Convert.ToInt32(c[0]);
                //label3.Text = c[0].ToString();
                try
                {
                    //一列目のカラーコード
                    if (textBox1.Text[0] == '0')
                    {
                        pictureBox2.BackColor = Color.Black;
                    }
                    else if (textBox1.Text[0] == '1')
                    {
                        pictureBox2.BackColor = Color.Brown;
                    }
                    else if (textBox1.Text[0] == '2')
                    {
                        pictureBox2.BackColor = Color.Red;
                    }
                    else if (textBox1.Text[0] == '3')
                    {
                        pictureBox2.BackColor = Color.Orange;
                    }
                    else if (textBox1.Text[0] == '4')
                    {
                        pictureBox2.BackColor = Color.Yellow;
                    }
                    else if (textBox1.Text[0] == '5')
                    {
                        pictureBox2.BackColor = Color.Green;
                    }
                    else if (textBox1.Text[0] == '6')
                    {
                        pictureBox2.BackColor = Color.Blue;
                    }
                    else if (textBox1.Text[0] == '7')
                    {
                        pictureBox2.BackColor = Color.Purple;
                    }
                    else if (textBox1.Text[0] == '8')
                    {
                        pictureBox2.BackColor = Color.Gray;
                    }
                    else if (textBox1.Text[0] == '9')
                    {
                        pictureBox2.BackColor = Color.White;
                    }
                    //二列目のカラーコード
                    if (textBox1.Text[1] == '0')
                    {
                        pictureBox3.BackColor = Color.Black;
                    }
                    else if (textBox1.Text[1] == '1')
                    {
                        pictureBox3.BackColor = Color.Brown;
                    }
                    else if (textBox1.Text[1] == '2')
                    {
                        pictureBox3.BackColor = Color.Red;
                    }
                    else if (textBox1.Text[1] == '3')
                    {
                        pictureBox3.BackColor = Color.Orange;
                    }
                    else if (textBox1.Text[1] == '4')
                    {
                        pictureBox3.BackColor = Color.Yellow;
                    }
                    else if (textBox1.Text[1] == '5')
                    {
                        pictureBox3.BackColor = Color.Green;
                    }
                    else if (textBox1.Text[1] == '6')
                    {
                        pictureBox3.BackColor = Color.Blue;
                    }
                    else if (textBox1.Text[1] == '7')
                    {
                        pictureBox3.BackColor = Color.Purple;
                    }
                    else if (textBox1.Text[1] == '8')
                    {
                        pictureBox3.BackColor = Color.Gray;
                    }
                    else if (textBox1.Text[1] == '9')
                    {
                        pictureBox3.BackColor = Color.White;
                    }

                    //三列目のカラーコード
                    if (textBox1.Text[2] == '0')
                    {
                        pictureBox4.BackColor = Color.Black;
                    }
                    else if (textBox1.Text[2] == '1')
                    {
                        pictureBox4.BackColor = Color.Brown;
                    }
                    else if (textBox1.Text[2] == '2')
                    {
                        pictureBox4.BackColor = Color.Red;
                    }
                    else if (textBox1.Text[2] == '3')
                    {
                        pictureBox4.BackColor = Color.Orange;
                    }
                    else if (textBox1.Text[2] == '4')
                    {
                        pictureBox4.BackColor = Color.Yellow;
                    }
                    else if (textBox1.Text[2] == '5')
                    {
                        pictureBox4.BackColor = Color.Green;
                    }
                    else if (textBox1.Text[2] == '6')
                    {
                        pictureBox4.BackColor = Color.Blue;
                    }
                    else if (textBox1.Text[2] == '7')
                    {
                        pictureBox4.BackColor = Color.Purple;
                    }
                    else if (textBox1.Text[2] == '8')
                    {
                        pictureBox4.BackColor = Color.Gray;
                    }
                    else if (textBox1.Text[2] == '9')
                    {
                        pictureBox4.BackColor = Color.White;
                    }
                }
            catch (IndexOutOfRangeException)
            {
                
            }
           // pictureBox2.BackColor = Color.Red;
        }

        public class ColorCode
        {
            public char ColorSelect(char c)
            {
                try
                {
                    if (c == 0)
                    {

                    }
                    else if (c == 1)
                    {

                    }
                    else if (c == 2)
                    {

                    }
                }
                catch (IndexOutOfRangeException)
                {

                }
                return c;
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }
    }
}
```



かなりソースコードが雑ですが．最初のアプリなので勘弁してください．
classにして各フォームと対応づける方法がわからなかった．教えてください．

最初に作ったVSアプリですが，楽しいですね．

こちらgithubのURL
https://github.com/Ooshita/Teikou