【发布时间】:2012-09-03 19:44:08
【问题描述】:
我正在创建一个简单的程序来将笔记跟踪到文本文件中。除了复选框之外,我的一切都正常工作。我需要它,您可以在其中选择所需的复选框并将其写入同一行的文件。如果未选择复选框或仅选择其中一些复选框,它也会转到下一行。下面是我目前拥有的代码,到目前为止它工作正常,除非我在每个复选框语句上使用 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();
}
}
【问题讨论】:
-
谢谢!这在人们不常见的地方很常见吗?大声笑,如果我不向你展示我正在使用的东西,你怎么能帮助我。
-
许多人喜欢从尽可能多的信息开始提问,只有在愿意提供帮助的人提出要求时才一点一点地提供信息。您会惊讶地发现有多少问题是以这种方式被问到的。
-
啊,我明白了。感谢您提供的信息,我会记住它以备后用,因为我相信我还有其他问题要问:)