簡體   English   中英

WPF 是否有保存單選按鈕內容的方法,然后通過事件處理程序發送保存內容

[英]Does WPF have a way of saving radio button content and then sent the save content through a event handler

我想知道 WPF 是否可以保存單選按鈕內容並使用事件處理程序將內容發送到文本文件。 我需要在事件處理程序中完成所有這些還是我可以調用某個類?

    public void method(){
string s = "Test1&Test2&Test3&Test4";

string[] s = Spliting.Split(new string[] { "&" }, StringSplitOptions.RemoveEmptyEntries);

List<RadioButton> radioButtonList = new List<RadioButton>();

        radioButtonList.Add(radioButton);
        radioButtonList.Add(radioButton1);

    for (int i = 0; i < radioButtonList.Count; i++)
{

//some code that insert string into the radio button (done)
//when i use streamwriter inside here, it give me this in the text file
//System.Windows.Controls.RadioButton Content IsChecked:False <- this can be turn to true if i put variable.Checked = true
}

private void radioButton_Checked(object sender, RoutedEventArgs e)
    {

        if (radioButton.IsChecked == true)
        {
            StreamWriter streamwriters = new StreamWriter ("Sent.txt", false);
            streamwriters.Close();
        }
        else if (radioButton1.IsChecked == true)
        {
            StreamWriter streamwriters = new StreamWriter("Sent.txt", false);
            streamwriters.Close();
        }

或者WPF有一個方法可以自動將內容保存到變量中。 我錯過了什么嗎?

我希望單選按鈕檢查單選按鈕並將內容發送到文本文件中。

如果您只想將使用單選按鈕顯示的文本保存到文件中,則:

private void radioButton1_Checked(object sender, EventArgs e)
{
    string radioButtonContent = ((RadioButton)sender).Text;
    string savePath = @"C:\sent.txt"; // or wherever

    File.WriteAllText(savePath, radioButtonContent);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM