我正在创建一个简单的程序来将笔记跟踪到文本文件中。除了复选框之外,我的一切都正常工作。我需要它,您可以在其中选择所需的复选框并将其写入同一行的文件。如果未选择复选框或仅选择其中一些复选框,它也会转到下一行。下面是我目前拥有的代码,到目前为止它工作正常,除非我在每个复选框语句上使用 Writeline,显然它会将每个复选框文本放在一个新行上。如果我只使用 Write 它可以工作,除了“tshooting_text.Text 与复选框文本在同一行结束。我对 C# 和一般编程有点陌生,所以如果我遗漏了一些简单的东西,请原谅我。无论如何这里是我到目前为止的代码。
private void copy_clipboard_button_Click(object sender, EventArgs e)
{
//Starts the file writer
using (StreamWriter sw = new StreamWriter("C:\\INET Portal Notes.txt"))
{
string CBRSame = cust_btn_text.Text;
if (cbr_same.Checked)
{
cust_callback_text.Text = CBRSame;
}
//Writes textboxes to the file
sw.WriteLine("**Name: " + cust_name_text.Text);
sw.WriteLine("**BTN: " + cust_btn_text.Text);
sw.WriteLine("**CBR: " + cust_callback_text.Text);
sw.WriteLine("**Modem: " + cust_modem_text.Text);
//Statements to write checkboxes to file
if (checkbox_pwr.Checked)
sw.Write("**Lights: PWR, ");
if (checkbox_e1.Checked)
sw.Write("E1, ");
if (checkbox_e2.Checked)
sw.Write("E2, ");
if (checkbox_e3.Checked)
sw.Write("E3, ");
if (checkbox_e4.Checked)
sw.Write("E4, ");
if (checkbox_wlan.Checked)
sw.Write("WLAN, ");
if (checkbox_dsl.Checked)
sw.Write("DSL, ");
if (checkbox_dslblink.Checked)
sw.Write("DSL Blinking, ");
if (checkbox_inet.Checked)
sw.Write("INET, ");
if (checkbox_inetred.Checked)
sw.Write("INET RED, ");
//Continues textboxes to file
sw.WriteLine("**Troubleshooting: " + tshooting_text.Text);
sw.WriteLine("**Services Offered: " + services_offered_text.Text);
sw.WriteLine("**Other Notes: " + other_notes_text.Text);
sw.Flush();
}
}