![](/img/trans.png)
[英]How do I string Split text in a text file into a text box and change the text of the radio button?
[英]How do I get the name/text of a radio button to be listed in an existing text file?
(文本文件以单独的形式创建)
这是我到目前为止所拥有的:
foreach (RadioButton rb in this.Controls)
if (rb.Checked)
{
StreamWriter details;
details = File.AppendText("User Details.txt");
details.WriteLine("Preferences:" + rb.Text);
}
When ran, it says: System.InvalidCastException: 'Unable to cast object of type 'System.Windows.Forms.TextBox' to type 'System.Windows.Forms.RadioButton'.'
您可以使用OfType<..>
指定所需的控件类型。 这将返回转换为指定类型的已过滤控件集合。
foreach (RadioButton rb in this.Controls.OfType<RadioButton>())
您需要导入 Linq 才能使用此扩展方法。
using System.Linq;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.