フォームに4つのボタンがあり、ボタンの上、下、左、右をクリックして単語を入力したいと思っています。ボタンによるテキスト入力
ユーザーが上下に行くことによって彼の文字、数字、記号を選択することができます。
左と右は単語の前後に行くためです。彼が現在の手紙を確認したい場合に備えて、彼は間違いを犯して前に進んだ。
これらは、これは私が今持っているものであり、それはしかし、作品
private int i;
public Form1()
{
InitializeComponent();
tbOutput.Text = word;
}
private void btnUp_Click(object sender, EventArgs e)
{
//We don't want the i to go above the array
if (i <= 39)
{
i = i + 1;
}
tbOutput.Text = word + Convert.ToString(wordsAndLetters[i]);
}
private void btnDown_Click(object sender, EventArgs e)
{
//We don't want the i to go below the array
if (i > 0)
{
i = i - 1;
}
tbOutput.Text = word + Convert.ToString(wordsAndLetters[i]);
}
private void btnRight_Click(object sender, EventArgs e)
{
tbOutput.Text = word;
sb.Append(wordsAndLetters[i]);
word = sb.ToString();
i = 0;
tbOutput.Clear();
tbOutput.Text = word;
}
private void btnLeft_Click(object sender, EventArgs e)
{
int lengthword = sb.Length;
sb.Remove(lengthword -1, 1);
word = sb.ToString();
tbOutput.Clear();
tbOutput.Text = word;
}
}
など、今、私たちは、ボタンに文字の間に行くためのオプションを与える必要があり、変数
private string word;
private StringBuilder sb = new StringBuilder();
private char[] wordsAndLetters = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ',', '.', '!', '?' };
ですそれは完璧ではない。私の現在のプログラムをより良くする方法はありますか?
'StringBuilder'と' .Append(char) 'を見てください。 –