欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#實(shí)現(xiàn)倒計時關(guān)閉提示框功能

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

前兩天實(shí)現(xiàn)某個功能需要做一個提示框 并且能夠自動關(guān)閉的,就從網(wǎng)上搜了一個能夠自動關(guān)閉的提示框 ,但由于我需要的場景是不確定計時時間的,所以并沒有使用到該窗體,但是我覺得可以留存?zhèn)溆?,后邊也把我這種倒計時的提示框用處還是很多的,用于自動彈窗 自動關(guān)閉 ,雖然在我的項(xiàng)目中沒有

其核心方法在 timer(TimerCallBack,Object,int32,int32) TimerCallBack 是一個委托 ,代表要執(zhí)行的方法,其用途可以用在各個定時去調(diào)用方法的場景,而且可以設(shè)置窗體的FormBorderStyle的屬性為None,設(shè)置窗體邊框和標(biāo)題欄外觀不顯示.

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 NewuView.Mix
{
  public partial class AutoCloseMessageBox : Form
  {
    public AutoCloseMessageBox()
    {
      InitializeComponent();
    }
    public void getMassage(string text)
    {
      label1.Text = text;
    }
    public void GetText(string caption)
    {
      this.Text = caption;
    }
    System.Threading.Timer _timeoutTimer;
    string _caption;
    AutoCloseMessageBox(string text, string caption, int timeout)
    {
      _caption = caption;
      _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
        null, timeout, System.Threading.Timeout.Infinite);
      AutoCloseMessageBox m_MassageBox = new AutoCloseMessageBox();
      m_MassageBox.getMassage(text);
      m_MassageBox.GetText(caption);
      m_MassageBox.ShowDialog();
    public static void Show(string text, string caption, int timeout)
    {
      new AutoCloseMessageBox(text, caption, timeout);
    }
    void OnTimerElapsed(object state)
    {
      IntPtr mbWnd = FindWindow(null, _caption);
      if (mbWnd != IntPtr.Zero)
        SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
      _timeoutTimer.Dispose();
    }
    const int WM_CLOSE = 0x0010;
    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
    static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
  }
}

調(diào)用時直接使用類名.show(text,captiom,timeout) 直接調(diào)用即可

下邊是當(dāng)時的項(xiàng)目使用場景的解決辦法

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 NewuView.Mix
{
  public partial class ErrorForm : Form
  {
    public ErrorForm()
    {
      InitializeComponent();
    }
    private void BarcodeErrorForm_Load(object sender, EventArgs e)
    {
      this.ShowInTaskbar = false;
    }
    public void Clear()
    {
      if (this.InvokeRequired)
      {
        this.BeginInvoke(new MethodInvoker(Clear));
      }
      else
      {
        this.richTextBox1.Clear();
      }
    }
    public void SetMsg(string msg)
    {
      if (this.InvokeRequired)
      {
        this.BeginInvoke(new Action<string>(SetMsg), msg);
      }
      else
      {
        this.richTextBox1.AppendText(msg + Environment.NewLine);
      }
    }
    public Point Point1 { get; set; }
    public void ShowForm()
    {
      if (this.InvokeRequired)
      {
        this.Invoke(new MethodInvoker(ShowForm));
      }
      else
      {
        this.Location = Point1;
        this.BringToFront();
        this.Visible = true;
      }
    }
    public void HideForm()
    {
      if (this.InvokeRequired)
      {
        this.Invoke(new MethodInvoker(HideForm));
      }
      else
      {
        this.richTextBox1.Clear();
        this.Visible = false;
      }
    }
  }
}

該窗體可以用于實(shí)時監(jiān)控某一個狀態(tài)時 而彈出的提示框 并根據(jù)狀態(tài)改變而隱藏

使用時,new一個該errorForm

在該窗體有一個RichTextBox,用來顯示提示信息,使用SetMsg,設(shè)置要顯示的信息

需要彈出時,實(shí)例調(diào)用Show()方法  實(shí)際就是講該窗體的visible屬性置為true,讓窗體顯示,并且調(diào)用Clear方法,清除提示信息

需要隱藏時,實(shí)例調(diào)用HideForm()方法,將窗體visible屬性設(shè)置為false,調(diào)用clear方法,清除提示信息

總結(jié)

以上所述是小編給大家介紹的C#實(shí)現(xiàn)倒計時關(guān)閉提示框功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對我們網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

上一篇:C#使用InstallerProjects打包桌面應(yīng)用程序的完整步驟

欄    目:C#教程

下一篇:C#窗口實(shí)現(xiàn)定時關(guān)機(jī)系統(tǒng)

本文標(biāo)題:C#實(shí)現(xiàn)倒計時關(guān)閉提示框功能

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/4704.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有