網站首頁 編程語言 正文
本文實例為大家分享了C#線程中彈窗的制作代碼,供大家參考,具體內容如下
首先建立一個ShowFrom窗體,窗體中放入兩個按鈕分別為確定和取消
分別在按鈕中添加如下事件
private void btn_ok_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? this.DialogResult = DialogResult.OK; ? ? ? ? ? ? this.Close(); ? ? ? ? } ? ? ? ? private void btn_cancle_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? this.DialogResult = DialogResult.Cancel; ? ? ? ? ? ? this.Close(); ? ? ? ? }
在主窗體中建立如下函數可以實現調用顯示彈窗
public static bool MsgShow(string msg = "未定義操作提示", bool bcancel = false) ? ? ? ? { ? ? ? ? ? ? //設備暫停,蜂鳴開始 ? ? ? ? ? ? // ? VAR.gsys_set.beep_en = true; ? ? ? ? ? ? Task<bool> mtask = new Task<bool> ? ? ? ? ? ? ? ? ( ? ? ? ? ? ? ? ? () => ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? lock (WarnObj) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? warning frWarning = new warning();//錯誤窗體 ? ? ? ? ? ? ? ? ? ? ? ? frWarning.TopMost = true; ? ? ? ? ? ? ? ? ? ? ? ? frWarning.BackColor = Color.Yellow; ? ? ? ? ? ? ? ? ? ? ? ? frWarning.lb_msg.Text = msg; ? ? ? ? ? ? ? ? ? ? ? ? if (bcancel) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? frWarning.btn_cancle.Visible = true; ? ? ? ? ? ? ? ? ? ? ? ? ? ? frWarning.btn_cancle.Enabled = true; ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? frWarning.ShowDialog(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? VAR.msg.AddMsg(Msg.EM_MSGTYPE.SAVE_WAR, string.Format("{0}", msg)); ? ? ? ? ? ? ? ? ? ? ? ? if (frWarning.DialogResult == DialogResult.OK) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? frWarning.Dispose(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? return true; ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else { ? ? ? ? ? ? ? ? ? ? ? ? ? ? frWarning.Dispose(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? return false; ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ?); ? ? ? ? ? ? mtask.Start(); ? ? ? ? ? ? mtask.Wait(); ? ? ? ? ? ? ? ? ? ? ? return mtask.Result; }
private void button1_Click_1(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? var ret = actiom.MsgShow("ceshi", true); ? ? ? ? ? ? if (ret) ? ? ? ? ? ? ? ? MessageBox.Show("ok"); ? ? ? ? ? ? else ? ? ? ? ? ? ? ? MessageBox.Show("err"); ? ? ? ? }
結果:
原文鏈接:https://blog.csdn.net/gy0124/article/details/102572656
相關推薦
- 2022-07-23 C++深入淺出探索數據結構的原理_C 語言
- 2022-04-08 Python編程-封裝,繼承與多態_python
- 2022-07-18 anaconda常用命令的整理
- 2022-11-30 詳解Python如何輕松實現定時執行任務_python
- 2022-06-12 PostgreSQL數據庫事務插入刪除及更新操作示例_PostgreSQL
- 2023-05-03 C++11學習之包裝器解析_C 語言
- 2022-10-14 使用docker起一個verdaccio的容器
- 2022-05-26 一起來學習C#的觀察者模式_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支