버그 템플릿을 만드는 프로그램을 만들었으며 텍스트를 제대로 저장하지 못하는 문제가 있습니다.ReadAllLines()를 사용하여 텍스트 파일을 열 때 줄 바꿈이 생깁니다. C#
내가 각 템플릿에 대한 모든 텍스트를 보유 TemplateTexts라는 텍스트 파일이 템플릿은 다음과 같습니다 -
REQUIREMENTS
- Example
ADDITIONAL REQUIREMENTS
- Example
- Example
-----COPY BELOW THIS LINE-----
을 프로그램이 텍스트 파일의 한 라인에 복사합니다 그 모두를 닫을 때. (이 모양)
REQUIREMENTS- Example ADDITIONAL REQUIREMENTS- Example - Example-----COPY BELOW THIS LINE-----
텍스트 파일에는 20 줄의 템플릿이 들어 있습니다. 템플릿은 텍스트 파일에 텍스트 한 줄로 저장되지만, 프로그램을 다시 열 때 첫 번째 예제에서 텍스트가 어떻게 표시되는지와 같이 한 줄의 텍스트가 여러 줄로 바뀝니다.
왜 이런 일이 벌어지고 있는지 알 수 있습니까? 또는 각 템플릿을 텍스트 파일에 저장하는 더 좋은 방법이있을 수 있습니다. 플래그 또는 다른 것으로 템플릿을 구분할 수 있습니까? 여기
내 프로그램 코드 : 당신은Text
속성에 대한
RichTextBox
을 물어 보면
public partial class Form1 : Form
{
static String buttonNamesPath = AppDomain.CurrentDomain.BaseDirectory + "/ButtonNames.txt";
String[] ButtonNames = System.IO.File.ReadAllLines(buttonNamesPath);
static String buttonTextPath = AppDomain.CurrentDomain.BaseDirectory + "/ButtonText.txt";
String[] ButtonText = System.IO.File.ReadAllLines(buttonTextPath);
private void SetupTextField()
{
comboBox1.Items.Clear();
comboBox2.Items.Clear();
for (int i = 0; i < ButtonNames.Length; i++)
{
comboBox1.Items.Insert(i, ButtonNames[i]);
comboBox2.Items.Insert(i, ButtonNames[i]);
}
}
public Form1()
{
InitializeComponent();
this.FormClosing += this.Form1_FormClosing;
}
private void Form1_Load(object sender, EventArgs e)
{
SetupTextField();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string comboBoxText;
comboBoxText = comboBox1.SelectedItem.ToString();
int strNumber;
int strIndex = 0;
for (strNumber = 0; strNumber < ButtonNames.Length; strNumber++)
{
strIndex = Array.FindIndex(ButtonNames, x => x.Contains(comboBoxText));
if (strIndex >= 0)
break;
}
ButtonNames[strIndex] = textBox1.Text;
ButtonText[strIndex] = richTextBox2.Text;
SetupTextField();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
System.IO.File.WriteAllLines(buttonNamesPath, ButtonNames);
System.IO.File.WriteAllLines(buttonTextPath, ButtonText);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
richTextBox1.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
string comboBoxText;
comboBoxText = comboBox2.SelectedItem.ToString();
int strNumber;
int strIndex = 0;
for (strNumber = 0; strNumber < ButtonNames.Length; strNumber++)
{
strIndex = Array.FindIndex(ButtonNames, x => x.Contains(comboBoxText));
if (strIndex >= 0)
break;
}
richTextBox1.Text = ButtonText[strIndex];
}
private void label3_Click(object sender, EventArgs e)
{
}
}
가 나는 또한 ButtonNames.txt 및 ButtonText.txt
는 설명 :
은 자세한 내용은이 질문의 답변을 참조하십시오. –"프로그램을 닫을 때": 어떤 프로그램입니까? 너 나 메모장? 파일을 쓰려면 코드가 어떻게 생겼을까요? 실제로 생각해 보니 "메모장"이라는 뜻의 간단하고 짧은 단어로 설명 할 수 있습니까? 왼쪽 상단 모서리에 파란색 아이콘이있는 창이 있습니까? –
얻을 수 없습니다 ... 메모장이 잘못 되었습니까? 아니면 응용 프로그램이 올바르게 작동하지 않습니까? – jcvegan