| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4649 人关注过本帖
标题:新手请教:使用单选按钮时,CheckedChanged事件如何激发
取消只看楼主 加入收藏
千面
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-2-25
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
新手请教:使用单选按钮时,CheckedChanged事件如何激发
学习编程时,在窗体上放了以下6个单选按钮,设置了变量buttonType,不知哪个地方没有设置正确,点击displayButton按钮时没有出现预期效果,说明单选按钮的CheckedChanged事件没有调用,请教各位!
        private MessageBoxButtons buttonType = MessageBoxButtons.RetryCancel;
        private void buttonType_CheckedChanged(object sender, EventArgs e)
        {
            if (sender == ok)
                buttonType = MessageBoxButtons.OK;
            else if (sender == okCancel)
                buttonType = MessageBoxButtons.OKCancel;
            else if (sender == abortRetryIgnore)
                buttonType = MessageBoxButtons.AbortRetryIgnore;
            else if (sender == yesNoCancel)
                buttonType = MessageBoxButtons.YesNoCancel;
            else if (sender == yesNo)
                buttonType = MessageBoxButtons.YesNo;
            else
                buttonType = MessageBoxButtons.RetryCancel;
        }
        private void displayButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("this is your custom messagebox", "custom messagebox", buttonType, MessageBoxIcon.Question, 0, 0);
            switch (result)
            {
                case DialogResult.OK:
                    displayLabel.Text = "ok was pressed";
                    break;
                case DialogResult.Cancel:
                    displayLabel.Text = "cancel was pressed";
                    break;
                case DialogResult.Abort:
                    displayLabel.Text = "Abort was pressed";
                    break;
                case DialogResult.Retry:
                    displayLabel.Text = "Retry was pressed";
                    break;
                case DialogResult.Ignore:
                    displayLabel.Text = "Ignore was pressed";
                    break;
                case DialogResult.Yes:
                    displayLabel.Text = "Yes was pressed";
                    break;
                case DialogResult.No:
                    displayLabel.Text = "No was pressed";
                    break;
            }
        }
搜索更多相关主题的帖子: 按钮 
2010-02-25 18:52
千面
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-2-25
收藏
得分:0 
谢谢回复!我的意思是:放6个单选按钮,在点击某个单选按钮时,要把这个事件用一个变量buttonType反映出来,然后被displayButton_Click函数调用,但是不可能为每个按钮都设置CheckedChanged事件,不知怎么实现好?
2010-02-26 08:53
千面
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-2-25
收藏
得分:0 
问题解决,谢谢5楼!谢谢大家!
2010-02-27 16:19
快速回复:新手请教:使用单选按钮时,CheckedChanged事件如何激发
数据加载中...
 
   



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

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