Skip to content

Instantly share code, notes, and snippets.

@mrgarita
Created November 21, 2017 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrgarita/cf40cecdd28083dd78dc1ba71e27fef6 to your computer and use it in GitHub Desktop.
Save mrgarita/cf40cecdd28083dd78dc1ba71e27fef6 to your computer and use it in GitHub Desktop.
英単語アプリ1:リストに単語が追加される
/*
* 英単語アプリ1
* プロトタイプ
* リストに単語が追加される
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace 英単語アプリ1
{
public partial class Form1 : Form
{
// 単語保存リスト
private List<string> tangoList = new List<string>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = Application.ProductName;
label1.Text = "英単語";
label2.Text = "日本語";
button1.Text = "追 加";
this.ActiveControl = this.textBox1; // textBox1.Focus()はフォームロード時は使えない
}
private void button1_Click(object sender, EventArgs e)
{
// 未入力なら何もしない
if (textBox1.Text == "" || textBox2.Text == "") return;
// 英語と日本語をタブ区切り文字列にする
string en = textBox1.Text;
string ja = textBox2.Text;
string tango = en + "\t" + ja;
// リストに追加
tangoList.Add(tango);
// リストボックスに追加
listBox1.Items.Add(tango);
// 追加後テキストボックスをクリア
textBox1.Text = textBox2.Text = "";
// フォーカスを移動
textBox1.Focus();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment