| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 837 人关注过本帖
标题:简单的加法运算判断正误
只看楼主 加入收藏
leejiliang
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-11-10
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
简单的加法运算判断正误
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a, b, c, d;
            radioButton1.Enabled = true;
            radioButton2.Enabled = true;
            radioButton1.Checked = false;
            radioButton2.Checked = false;
            Random rnd = new Random();
            a = rnd.Next(99);
            b = rnd.Next(99);
            c = a + b;
            d = rnd.Next(c - 1, c + 1);
            textBox1.Text = Convert.ToString(a);
            textBox2.Text = Convert.ToString(b);
            textBox3.Text = Convert.ToString(d);
            button1.Enabled = false;
            radioButton1.Enabled = true;
            radioButton2.Enabled = true;
           label3.Text = "请选择";
             }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            int a, b, c, d;

            a = Convert.ToInt32(textBox1.Text);
            b = Convert.ToInt32(textBox2.Text);
            c = Convert.ToInt32(textBox3.Text);
            d = a + b;
            if (c == d)
            {
                label3.Text = "判断正确";
            }
            else
                label3.Text = "判断错误";
            radioButton1.Enabled = false;
            radioButton2.Enabled = false;
           button1.Enabled = true;

        }
         private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            int a, b, c, d;

            a = Convert.ToInt32(textBox1.Text);
            b = Convert.ToInt32(textBox2.Text);
            c = Convert.ToInt32(textBox3.Text);
            d = a + b;
            if (c == d)
            {
                label3.Text = "判断错误";
            }
            else
                label3.Text = "判断正确";
            radioButton1.Enabled = false;
            radioButton2.Enabled = false;
            button1.Enabled = true;
    }
   }
  }


中间红色部分为什么要写两遍才能实现Butten和radiobutten两者的enable属性轮流在true和false之间切换!
搜索更多相关主题的帖子: 正误 加法 运算 判断 
2010-11-10 13:37
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:5 
恩 是这样的 如果觉着麻烦可以这样写 radioButton1.Enabled =!radioButton1.Enabled button1.Enabled =!button1.Enabled

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-11-10 13:48
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:5 
写一个函数。
程序代码:
void SetRadioBoxEnableAndChecked( RadioBox rb, bool enableAndChecked)
{
    if ( rb != null)
    {
        rb.Checked = !rb.Enable = enableAndChecked;
    }
}
2010-11-10 14:04
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:5 
因为你在radioButton1_CheckedChanged和radioButton2_CheckedChanged的事件中都是用了radioButton1.Enabled = false;和 radioButton2.Enabled = false;
所以要写两遍才能实现Butten和radiobutten两者的enable属性。
2010-11-10 22:21
欲与天斗
Rank: 4
等 级:业余侠客
帖 子:88
专家分:270
注 册:2010-10-6
收藏
得分:5 
路过
2010-11-16 09:25
快速回复:简单的加法运算判断正误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015618 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved