日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C#線程中彈窗的制作方法_C#教程

作者:機器俠客 ? 更新時間: 2022-04-18 編程語言

本文實例為大家分享了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

欄目分類
最近更新