如何将另一个盒子中的单选按钮相加? [英] how to sum radio buttons in another box?

查看:74
本文介绍了如何将另一个盒子中的单选按钮相加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个12使用单选按钮进行多项选择测验的问题,我怎样才能在最后总结测验结果,告诉参加测验的人有多少是正确的,错误的以及最终得分是多少。  我想用混合创建一个测验。  我不需要将数据保存在数据库中。  我只需要使用单选按钮,多项选择就可以得到大约10-12个问题。  然后在测验结束时,它将记录正确的答案,并说你有12个中的9个正确,80%。   

推荐答案

你好lehi53

这个像你描述的小测验有两个问题,每一个都有三个错误的答案和一个右边你有一个按钮来计算并在textBox中显示结果

试试它并希望能帮到你


XAML代码:


< Grid x:Name =" LayoutRoot">
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < Grid.RowDefinitions>
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RowDefinition Height =" 0.558 *" />
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RowDefinition Height =" 0.442 *" />
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RowDefinition Height =" 58.786" />
    &NBSP;&NBSP;&NBSP; < /Grid.RowDefinitions>
    &NBSP;&NBSP;&NBSP; < Grid x:Name =" Grid1">
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < Label Horizo​​ntalAlignment =" Left"余量= QUOT; 8,18,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 210"高度= QUOT; 38"内容="问题1?" />    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto1_1"的Horizo​​ntalAlignment = QUOT;左"余量= QUOT; 37,68,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 83"高度= QUOT; 25"内容="错误"/>
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto1_2"的Horizo​​ntalAlignment = QUOT;左"余量= QUOT; 169,68,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 74"高度= QUOT; 25"内容="错误"/>
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto1_3"的Horizo​​ntalAlignment = QUOT;右"余量= QUOT; 0,68,192,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 111"高度= QUOT; 25" Content =" Right" />
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto1_4"的Horizo​​ntalAlignment = QUOT;右"余量= QUOT; 0,68,94,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 59"高度= QUOT; 25"内容="错误"/>
    &NBSP;&NBSP;&NBSP; < / Grid>
    &NBSP;&NBSP;&NBSP; < Grid x:Name =" Grid2" Grid.Row =" 1">
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < Label Horizo​​ntalAlignment =" Left"余量= QUOT; 6,26.928,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 210"高度= QUOT; 38" Content =" Question 2?" />
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto2_1"的Horizo​​ntalAlignment = QUOT;左"余量= QUOT; 35,76.928,0,0"宽度= QUOT; 111"含量="右" VerticalAlignment = QUOT;陀螺"高度="25"/>    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto2_2"的Horizo​​ntalAlignment = QUOT;左"余量= QUOT; 167,76.928,0,0"宽度= QUOT; 69"含量="错误" VerticalAlignment = QUOT;陀螺"高度="25"/>    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto2_3"的Horizo​​ntalAlignment = QUOT;右"余量= QUOT; 0,76.928,194,0"宽度= QUOT; 111"含量="错误" VerticalAlignment = QUOT;陀螺"高度="25"/>    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < RadioButton x:Name =" RadioButto2_4"的Horizo​​ntalAlignment = QUOT;右"余量= QUOT; 0,76.928,92,0"宽度= QUOT; 63"含量="错误" VerticalAlignment = QUOT;陀螺"高度="25"/>    &NBSP;&NBSP;&NBSP; < / Grid>
    &NBSP;&NBSP;&NBSP; < Button Margin =" 0,18.786,161,19"含量="结果" Grid.Row = QUOT; 2英寸的Horizo​​ntalAlignment = QUOT;右"宽度= QUOT; 80 QUOT;点击=" ResultButto" />
    &NBSP;&NBSP;&NBSP; < TextBox x:Name =" txtResult"余量= QUOT; 0,18.786,19,19" Grid.Row = QUOT; 2英寸TextWrapping = QUOT;包覆与QUOT;的Horizo​​ntalAlignment = QUOT;右"宽度=" 112" />    < / Grid>
ResultButton事件代码

private void ResultButto(object sender,System.Windows.RoutedEventArgs e)
    &NBSP;&NBSP;&NBSP; {
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; // TODO:在这里添加事件处理程序实现。
    &NBSP;&NBSP;&NBSP;
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; int result = 0;
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; if(this.RadioButto1_3.IsChecked == true)
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;结果++;
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; if(this.RadioButto2_1.IsChecked == true)
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;结果++;
    &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; txtResult.Text = result.ToString();

    &NBSP;&NBSP;&NBSP;你是-------------------
穆罕默德·萨布里
Hi lehi53

This small quiz like you described with two questions each one have three wrong answers and one right
you have a button to calculate and show the result in textBox

try it and hope to help you


XAML Code:


<Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="0.558*"/>
            <RowDefinition Height="0.442*"/>
            <RowDefinition Height="58.786"/>
        </Grid.RowDefinitions>
        <Grid x:Name="Grid1">
            <Label HorizontalAlignment="Left" Margin="8,18,0,0" VerticalAlignment="Top" Width="210" Height="38" Content="Question 1?"/>
            <RadioButton x:Name="RadioButto1_1" HorizontalAlignment="Left" Margin="37,68,0,0" VerticalAlignment="Top" Width="83" Height="25" Content="Wrong"/>
            <RadioButton x:Name="RadioButto1_2" HorizontalAlignment="Left" Margin="169,68,0,0" VerticalAlignment="Top" Width="74" Height="25" Content="Wrong"/>
            <RadioButton x:Name="RadioButto1_3" HorizontalAlignment="Right" Margin="0,68,192,0" VerticalAlignment="Top" Width="111" Height="25" Content="Right"/>
            <RadioButton x:Name="RadioButto1_4" HorizontalAlignment="Right" Margin="0,68,94,0" VerticalAlignment="Top" Width="59" Height="25" Content="Wrong"/>
        </Grid>
        <Grid x:Name="Grid2" Grid.Row="1">
            <Label HorizontalAlignment="Left" Margin="6,26.928,0,0" VerticalAlignment="Top" Width="210" Height="38" Content="Question 2?"/>
            <RadioButton x:Name="RadioButto2_1" HorizontalAlignment="Left" Margin="35,76.928,0,0" Width="111" Content="Right" VerticalAlignment="Top" Height="25"/>
            <RadioButton x:Name="RadioButto2_2" HorizontalAlignment="Left" Margin="167,76.928,0,0" Width="69" Content="Wrong" VerticalAlignment="Top" Height="25"/>
            <RadioButton x:Name="RadioButto2_3" HorizontalAlignment="Right" Margin="0,76.928,194,0" Width="111" Content="Wrong" VerticalAlignment="Top" Height="25"/>
            <RadioButton x:Name="RadioButto2_4" HorizontalAlignment="Right" Margin="0,76.928,92,0" Width="63" Content="Wrong" VerticalAlignment="Top" Height="25"/>
        </Grid>
        <Button Margin="0,18.786,161,19" Content="Result" Grid.Row="2" HorizontalAlignment="Right" Width="80" Click="ResultButto"/>
        <TextBox x:Name="txtResult" Margin="0,18.786,19,19" Grid.Row="2" TextWrapping="Wrap" HorizontalAlignment="Right" Width="112"/>
    </Grid>



ResultButton event code

private void ResultButto(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
       
            int result=0;
            if(this.RadioButto1_3.IsChecked==true)
                result++;
            if(this.RadioButto2_1.IsChecked==true)
                result++;
            txtResult.Text=result.ToString();

        }




-------------------
Mohamed Sabry


这篇关于如何将另一个盒子中的单选按钮相加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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