C#線程中彈窗的制作方法
本文實(shí)例為大家分享了C#線程中彈窗的制作代碼,供大家參考,具體內(nèi)容如下
首先建立一個(gè)ShowFrom窗體,窗體中放入兩個(gè)按鈕分別為確定和取消
分別在按鈕中添加如下事件
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(); ? ? ? ? }
在主窗體中建立如下函數(shù)可以實(shí)現(xiàn)調(diào)用顯示彈窗
public static bool MsgShow(string msg = "未定義操作提示", bool bcancel = false) ? ? ? ? { ? ? ? ? ? ? //設(shè)備暫停,蜂鳴開始 ? ? ? ? ? ? // ? VAR.gsys_set.beep_en = true; ? ? ? ? ? ? Task<bool> mtask = new Task<bool> ? ? ? ? ? ? ? ? ( ? ? ? ? ? ? ? ? () => ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? lock (WarnObj) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? warning frWarning = new warning();//錯(cuò)誤窗體 ? ? ? ? ? ? ? ? ? ? ? ? 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"); ? ? ? ? }
結(jié)果:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#中循環(huán)語句:while、for、foreach的使用
本篇文章主要介紹了C#中的三種循環(huán)語句(while、for、foreach)的實(shí)現(xiàn)方式,需要的朋友可以參考下2015-07-07C#無法打開計(jì)算機(jī)“.”上的 IISADMIN 服務(wù)的解決方法
在使用c#進(jìn)行控制IIS服務(wù)啟動(dòng)停止的時(shí)候,提示:無法打開計(jì)算機(jī)“.”上的 IISADMIN 服務(wù)2015-01-01Unity實(shí)現(xiàn)物體跟隨鼠標(biāo)移動(dòng)
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)物體跟隨鼠標(biāo)移動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01C#實(shí)現(xiàn)OFD格式與PDF格式的互轉(zhuǎn)
OFD格式的文檔是一種我國獨(dú)有的國家標(biāo)準(zhǔn)版式的文檔。本文將通過C#程序介紹如何實(shí)現(xiàn)由OFD與PDF的互相轉(zhuǎn)換,感興趣的小伙伴可以了解一下2022-02-02