1
outputLabel을 모스 부호가 출력되는 레이블 제어 상자로 만들려고합니다. 왜 첫 번째 모스 부호 문자 만 표시되는지는 모르지만 나머지 코드는 표시되지 않습니다. 당신은 추가, 완전히 새로운 값으로 텍스트 속성을하지 설정하는모스 부호 변환기는 한 문자 만 출력합니다. C#
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 MorseCode
{
public partial class morseCodeForm : Form
{
public morseCodeForm()
{
InitializeComponent();
}
//Anthony Rosamilia
//Make a key,value system to translate the user text.
//Make sure usertext appears only in lower case to minimise errors.
private void convertButton_Click(object sender, EventArgs e)
{
Dictionary<char, String> morseCode = new Dictionary<char, String>()
{
{'a' , ".-"},{'b' , "-..."},{'c' , "-.-."}, //alpha
{'d' , "-.."},{'e' , "."},{'f' , "..-."},
{'g' , "--."},{'h' , "...."},{'i' , ".."},
{'j' , ".---"},{'k' , "-.-"},{'l' , ".-.."},
{'m' , "--"},{'n' , "-."},{'o' , "---"},
{'p' , ".--."},{'q' , "--.-"},{'r' , ".-."},
{'s' , ".-."},{'t' , "-"},{'u' , "..-"},
{'v' , "...-"},{'w' , ".--"},{'x' , "-..-"},
{'y' , "-.--"},{'z' , "--.."},
//Numbers
{'0' , "-----"},{'1' , ".----"},{'2' , "..----"},{'3' , "...--"},
{'4' , "....-"},{'5' , "....."},{'6' , "-...."},{'7' , "--..."},
{'8' , "---.."},{'9' , "----."},
};
string userText = inputTextBox.Text;
userText = userText.ToLower();
for (int index = 0; index < userText.Length; index++)
{
/* if (index > 0)
{
outLabel.Text = ('/').ToString();
}
*/char t = userText[index];
if (morseCode.ContainsKey(t))
{
outLabel.Text = (morseCode[t]);
}
}
}
private void clearButton_Click(object sender, EventArgs e)
{
inputTextBox.Text = "";
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
+1. 사이드 노트 : 'ToLower'는 대문자/소문자의 모스 부호가 없기 때문에 유용 할 수 있습니다. –
이것은 완벽합니다. 나는 당신의 속도와 복수 응답에 감사드립니다. 나는 항상 더 효율적인 경로를 시도 할 것이다. – Adreamer82
@AlexeiLevenkov : 좋은 전화 –