我想重新加載當前窗體(而不是主窗體),只要這兩個單選按鈕都未選中。我這樣做,但它不會工作。如何重新加載/重新打開相同的窗體C#
StreamWriter sw;
using (sw = File.CreateText(path))
{
if (OnewayRadio.Checked == true)
{
sw.WriteLine("One Way Ticket");
}
else if (RoundRadio.Checked == true)
{
sw.WriteLine("Round Trip");
}
else
{
MessageBox.Show("You have not selected your type of trip!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
sw.Close();
File.Delete(path);
sw = File.CreateText(path);
}
sw.WriteLine("Name: " + name.Text);
sw.WriteLine("Number: " + number.Text);
}
你說的目前的形式是什麼意思?它是您的應用程序中的主要形式還是您從另一種形式打開它? –
無論你在做什麼,都不要關閉StreamWriter,刪除文件,然後嘗試寫入它。這將是一個問題。 –
此外,您發佈的代碼段中沒有任何內容與關閉或打開表單有關。 –