代码:
//
//答题区域
//
int i = 1;
int sum = 0;
int sumA;
bool b1, b2, b3, b4, b5, b6 = false;
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
b1 = true;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
b2 = true;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
b3 = true;
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
b4 = true;
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
b5 = true;
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
b6 = true;
}
private void button1_Click(object sender, EventArgs e)
{
i++;
string[] line = System.IO.File.ReadAllLines(@"题.txt",Encoding.Default);//应用题文本,并把没行作为一个元素
string s = string.Format("{0}、",i);
foreach (string item in line)
{
if (item.StartsWith(s))
{
string[] strs = item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (strs.Length == 7)//如果strs的长度有7个元素。即有6个选项
{
string topic = strs[0];//第一个元素作为题目
string tabA = strs[1];//第二个元素作为选项A
string tabB = strs[2];//下同
string tabC = strs[3];
string tabD = strs[4];
string tabE = strs[5];
string tabF = strs[6];
labelTopic.Text = topic;
radioButtonTopA.Text = tabA;
radioButtonTopB.Text = tabB;
radioButtonTopC.Text = tabC;
radioButtonTopD.Text = tabD;
radioButtonTopE.Text = tabE;
radioButtonTopF.Text = tabF;
}
else if (strs.Length == 6)//如果strs的长度有6个元素。即有5个选项
{
string topic = strs[0];
string tabA = strs[1];
string tabB = strs[2];
string tabC = strs[3];
string tabD = strs[4];
string tabE = strs[5];
labelTopic.Text = topic;
radioButtonTopA.Text = tabA;
radioButtonTopB.Text = tabB;
radioButtonTopC.Text = tabC;
radioButtonTopD.Text = tabD;
radioButtonTopE.Text = tabE;
radioButtonTopF.Text = "";
}
else if (strs.Length == 5)//如果strs的长度有5个元素。即有4个选项
{
string topic = strs[0];
string tabA = strs[1];
string tabB = strs[2];
string tabC = strs[3];
string tabD = strs[4];
labelTopic.Text = topic;
radioButtonTopA.Text = tabA;
radioButtonTopB.Text = tabB;
radioButtonTopC.Text = tabC;
radioButtonTopD.Text = tabD;
radioButtonTopE.Text = "";//text为空
radioButtonTopF.Text = "";
}
//
//答题区域
//
int i = 1;
int sum = 0;
int sumA;
bool b1, b2, b3, b4, b5, b6 = false;
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
b1 = true;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
b2 = true;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
b3 = true;
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
b4 = true;
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
b5 = true;
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
b6 = true;
}
private void button1_Click(object sender, EventArgs e)
{
i++;
string[] line = System.IO.File.ReadAllLines(@"题.txt",Encoding.Default);//应用题文本,并把没行作为一个元素
string s = string.Format("{0}、",i);
foreach (string item in line)
{
if (item.StartsWith(s))
{
string[] strs = item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (strs.Length == 7)//如果strs的长度有7个元素。即有6个选项
{
string topic = strs[0];//第一个元素作为题目
string tabA = strs[1];//第二个元素作为选项A
string tabB = strs[2];//下同
string tabC = strs[3];
string tabD = strs[4];
string tabE = strs[5];
string tabF = strs[6];
labelTopic.Text = topic;
radioButtonTopA.Text = tabA;
radioButtonTopB.Text = tabB;
radioButtonTopC.Text = tabC;
radioButtonTopD.Text = tabD;
radioButtonTopE.Text = tabE;
radioButtonTopF.Text = tabF;
}
else if (strs.Length == 6)//如果strs的长度有6个元素。即有5个选项
{
string topic = strs[0];
string tabA = strs[1];
string tabB = strs[2];
string tabC = strs[3];
string tabD = strs[4];
string tabE = strs[5];
labelTopic.Text = topic;
radioButtonTopA.Text = tabA;
radioButtonTopB.Text = tabB;
radioButtonTopC.Text = tabC;
radioButtonTopD.Text = tabD;
radioButtonTopE.Text = tabE;
radioButtonTopF.Text = "";
}
else if (strs.Length == 5)//如果strs的长度有5个元素。即有4个选项
{
string topic = strs[0];
string tabA = strs[1];
string tabB = strs[2];
string tabC = strs[3];
string tabD = strs[4];
labelTopic.Text = topic;
radioButtonTopA.Text = tabA;
radioButtonTopB.Text = tabB;
radioButtonTopC.Text = tabC;
radioButtonTopD.Text = tabD;
radioButtonTopE.Text = "";//text为空
radioButtonTopF.Text = "";
}