【发布时间】:2021-08-02 13:53:29
【问题描述】:
我有一个问题要问你。我想将我的 WPF 应用程序设置为仅将我的 RadioButton 更改为他们自己的内容。我正在尝试创建一个数学测验,用户可以在其中选择三个选项之一。
我试过了:
List<string> list = new List<string> { "1", "2", "3" };//is there any way to add those options here?
public void ShuffleText()
{
var rand = new Random();
var shuffledText = list.OrderBy(x => rand.Next(list.Count)).ToList();
var radioButtons = new[] { firstOption, secondOption, thirdOption };
for (int i = 0; i < radioButtons.Length; i++)
{
radioButtons[i].Content = shuffledText[i];
}
}
private void control_Click(object sender, RoutedEventArgs e)
{
timer.Value += 1;
shiftTimer.Start();
if (vybOp == 0 || vybOp == 2 || vybOp == 4 || vybOp == 6)//this is enumeration selected operations
{
var answerRadioButtons = new RadioButton[] { firstOption, secondOption, thirdOption };
var correctAnswerButtonFound = false;
foreach (var answerButton in answerRadioButtons)
{
if (answerButton.IsChecked==true)
{
if (answerButton.Content == result.Text)
{
correctAnswerButtonFound = true;
}
}
}
if (correctAnswerButtonFound)
{
shiftTimer.Stop();
call.Text = "Correct";
count++;
numberOfExamples.Text = count.ToString();
Random second = new Random();
Random first = new Random();
int maxFirst = 10;
int maxSecond = 10;
int secondN = second.Next(2, maxSecond);
int firstN = secondN * first.Next(1, maxFirst / secondN);
if (mark.Text == "+")
{
int total = (firstN + secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
if (mark.Text == "-")
{
int total = (firstN - secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
if (mark.Text == "*")
{
int total = (firstN * secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
if (mark.Text == "/")
{
int residue = (firstN % secondN);
if (residue == 0)
{
int total = (firstN / secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
}
timer.Value = 0;
shiftTimer.Start();
}
else
{
shiftTimer.Stop();
call.Text = "Wrong";
poch++;//number of error
count++;
numberOfError.Text = poch.ToString();
numberOfExample.Text = count.ToString();
Random second = new Random();
Random first = new Random();
int maxFirst = 10;
int maxSecond = 10;
int secondN = second.Next(2, maxSecond);
int firstN = secondN * first.Next(1, maxFirst / secondN);
if (mark.Text == "+")
{
int total = (firstN + secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
if (mark.Text == "-")
{
int total = (firstN - secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
if (mark.Text == "*")
{
int total = (firstN * secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
if (zmark.Text == "/")
{
int residue = (firstN % secondN);
if (residue == 0)
{
int total = (firstN / secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
}
}
timer.Value = 0;
shiftTimer.Start();
if (poch == 4)
{
mt.Stop();
timer.Value = 0;
shiftTimer.Stop();
MessageBox.Show("Game Over!");
end_Click(sender, e);
}
}
我更喜欢将整个代码发送到这里,以免遗漏任何东西(是的,它写得不好,但可能是功能性的)。我的问题是我想给 Radiobutton(firstOption, secondOption, thirdOption) 赋值给他们的内容,这样一个是正确的。我会根据各个示例中的标记来分配值(例如
if (mark.Text == "+")
{
int total = (firstN + secondN);
firstT.Text = firstN.ToString();
secondT.Text = secondN.ToString();
result.Text = total.ToString();
}
但我不知道如何分配它。
如果有人有任何问题,请在 cmets 中写信给我,对于语言的组合,我深表歉意。我希望我的意思至少有点明显。
【问题讨论】:
-
你好!您应该始终使用英文变量名。对于不会说您的语言的人来说,阅读这篇文章真的很难。这样更多人可以参与到您的问题中。
-
@Papriker 好的,我会重写
-
@Papriker也许会更好
-
您不知道如何设置
Content属性或者您的问题到底是什么? -
@mm8 没错,我想设置
Content
标签: c# wpf list radio-button