winforms开发-弹出短暂提示消息 发表于 2024-10-29 | 更新于: 2024-10-29 | 分类于 客户端 , windows , winforms | 阅读次数: | 浏览量 不多说,且看代码即可,123456789101112131415161718192021222324252627282930313233343536373839404142434445private void ShowMessageBoxWithTimeout(string message, int timeout){ // 创建提示框 Form messageBoxForm = new Form() { Width = 300, Height = 150, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "提示", StartPosition = FormStartPosition.CenterScreen }; Label messageLabel = new Label() { TextAlign = ContentAlignment.MiddleCenter, AutoSize = true, Text = message, Left = 50, Top = 50 }; messageBoxForm.Controls.Add(messageLabel); // 显示提示框 messageBoxForm.Show(); // 设置定时器关闭提示框 System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() { Interval = timeout }; timer.Tick += (sender, e) => { timer.Stop(); messageBoxForm.Close(); }; timer.Start();}// 添加一个btn绑定此事件private void button1_Click(object sender, EventArgs e){ ShowMessageBoxWithTimeout("这是一个提示消息!", 3000);}好了,记录到这里,持续更新中。记录问题也是一种修行。书山有路勤为径,学海无涯苦作舟。欢迎关注微信公众号:【乐知付加密平台】,您的网络资源可变现一起学习,一起进步。-------------本文结束感谢您的阅读-------------