开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 875|回复: 8
收起左侧

[已解决] C#时钟信息框问题

 关闭 [复制链接]
结帖率:95% (84/88)
发表于 2023-4-4 14:45:42 | 显示全部楼层 |阅读模式   美国
15精币
奇怪的BUG又增加了。。。。
运行这代码,结果时钟弹窗连续弹3个(已经确认不是时钟导致的,周期8000,点击确认后立即弹窗,总共弹3次,本应该只弹一次)

恳切各位大佬帮忙指点,如果我有表达不明白的地方尽管问。
用的是Win11系统,VS2019。
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("222", "111", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            MessageBox.Show("222", "111", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }
    }
}


最佳答案

查看完整内容

Form1.Designer.cs [mw_shl_code=csharp,true]// // timer1 // this.timer1.Enabled = true; this.timer1.Interval = 8000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // timer2 // this.timer2.Enabled = true; this.timer2.Interval = 8000; this.timer2. ...

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳
结帖率:95% (84/88)
 楼主| 发表于 2023-4-4 15:12:58 | 显示全部楼层   美国
YongMeiSheng 发表于 2023-4-4 15:00
代码太片面了 看不出问题

大佬测试是没有问题的吗?我这上传个附件,请大佬看看哪里有问题。

test.zip

157.13 KB, 下载次数: 2

回复

使用道具 举报

结帖率:93% (13/14)

签到天数: 2 天

发表于 2023-4-4 14:45:43 | 显示全部楼层   重庆市重庆市
Form1.Designer.cs
[C#] 纯文本查看 复制代码
// 
            // timer1
            // 
            this.timer1.Enabled = true;
            this.timer1.Interval = 8000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // timer2
            // 
            this.timer2.Enabled = true;
            this.timer2.Interval = 8000;
            this.timer2.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // timer3
            // 
            this.timer3.Enabled = true;
            this.timer3.Interval = 8000;
            this.timer3.Tick += new System.EventHandler(this.timer1_Tick);

界面上把timer移开,你会发现,你弄了3个timer

补充内容 (2023-4-4 17:07):
3个timer的事件,都绑定到Form1::timer1_Tick了

评分

参与人数 1荣誉 +1 收起 理由
项目部004 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

结帖率:94% (59/63)
发表于 2023-4-4 15:00:50 | 显示全部楼层   香港特别行政区*
代码太片面了 看不出问题
回复

使用道具 举报

结帖率:100% (1/1)

签到天数: 3 天

发表于 2023-4-4 15:03:20 | 显示全部楼层   河南省郑州市
把 timer1_Tick 里的代码 注释掉 再试试

补充内容 (2023-4-4 15:04):
或者你把弹出的内容 改成不一样的  这样不是方便查看么?

点评

刚刚传了个附件,请大佬看看。   美国  发表于 2023-4-4 15:13
回复

使用道具 举报

结帖率:95% (84/88)
 楼主| 发表于 2023-4-4 15:07:29 | 显示全部楼层   美国
afu45 发表于 2023-4-4 15:03
把 timer1_Tick 里的代码 注释掉 再试试

补充内容 (2023-4-4 15:04):

真奇怪了,改成这个代码就是轮着弹出3遍:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("222", "111", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            MessageBox.Show("28822", "111", MessageBoxButtons.OK, MessageBoxIcon.Error);
            MessageBox.Show("2882dd2", "111", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }
    }
}
回复

使用道具 举报

结帖率:89% (8/9)

签到天数: 2 天

发表于 2023-4-4 17:12:59 | 显示全部楼层   广东省东莞市
像这种问题,你下个断点就很清楚了。
回复

使用道具 举报

结帖率:95% (84/88)
 楼主| 发表于 2023-4-5 00:59:18 | 显示全部楼层   美国
神女软件定制 发表于 2023-4-4 17:05
Form1.Designer.cs
[mw_shl_code=csharp,true]//
            // timer1

666,我vs2019界面上只找到一个timer3,剩下那俩右边下拉菜单栏能看见,但是选择之后不知道怎么删,原来还能直接看代码

评分

参与人数 1精币 +3 收起 理由
明天自然醒 + 3 咋又偷偷卷起来了

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报QQ: 793400750,邮箱:wp@125.la
网站简介:精易论坛成立于2009年,是一个程序设计学习交流技术论坛,隶属于揭阳市揭东区精易科技有限公司所有。
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表