我可以设置带有字符串的复选框名称吗? [英] c# can i set a checkboxes name with a string?

查看:78
本文介绍了我可以设置带有字符串的复选框名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我想做的是使用 settLoadBooleans 来更改基于加载的文本文件的复选框状态,问题是我需要设置名称

So basically what im trying to do is using settLoadBooleans as changing the checkboxes state based on a text file that got loaded, the problem is i need to set the name of the checkbox using the string i got from that text file.

在公共局部类MainForm:表单中

in "public partial class MainForm : Form"

public static string curDir = System.IO.Directory.GetCurrentDirectory();
public static string settingsdnt = curDir + @"\settings.dnt";
public static int settNo = 1;
public static string[] readSettdnt = File.ReadAllLines(settingsdnt);

public void MainForm_Load(object sender, EventArgs e)
    {
        Settings.VibeCheck();

        string getLineForBool = readSettdnt[settNo - 1].Substring(readSettdnt[settNo - 1].IndexOf(":") + 1);
        string getLineName = readSettdnt[settNo - 1].Substring(readSettdnt[settNo - 1].LastIndexOf(':') + 1);

        for (; settNo < 128; settNo++)
        {
            if (getLineForBool == "True" || getLineForBool == "False")
            {
                settLoadBooleans(getLineName);
            }
        }
    }

public static void settLoadBooleans(string settName)
    {
        string getLine = readSettdnt[settNo - 1].Substring(readSettdnt[settNo - 1].IndexOf(":") + 1);
        //thats where i need to change the string to checkbox
        if (getLine == "True")
        {
            settNameCb.Checked = true;
        }
        else
        {
            settNameCb.Checked = false;
        }
    }

在班级设置中

public static string curDir = System.IO.Directory.GetCurrentDirectory();

public static void VibeCheck()
{
    FileStream fs = File.Create(curDir + @"\settings.dnt");
    fs.Close();
    using (StreamWriter sw = File.AppendText(curDir + @"\settings.dnt"))
        {
        for (int i = 0; i < 128; i++)
            {
                sw.WriteLine("");
            }
        sw.Close();
        }
}

最后,我想做什么是:当 settNo 在:之后命中具有 True或 False字符串的行时,应将复选框名称更改为从我们命中的该行创建的字符串之前,请在:之前加入:

In the end of this, what im trying to do is: When settNo hits a line that has "True" or "False" string after ":" it should change the checkboxes name to the string that created from that line we hit before and take the part before ":"

推荐答案

首先,您应该从

if (getLineForBool == "True" && getLineForBool == "False")

if (getLineForBool == "True" || getLineForBool == "False")

然后按如下所示更改

public static void settLoadBooleans(string settName)
{
     string getLine = readSettdnt[settNo - 1].Substring(readSettdnt[settNo - 1].IndexOf(":") + 1);

     //thats where i need to change the string to checkbox
     settNameCb.Text = settName;

     if (getLine == "True")
     {   
         settNameCb.Checked = true;
     }
     else
     {
        settNameCb.Checked = false;
     }
}

这篇关于我可以设置带有字符串的复选框名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆