C 實現倒計時關閉提示框功能

2022-09-26 02:45:09 字數 2271 閱讀 4683

前兩天實現某個功能需要做乙個提示框 並且能夠自動關閉的,就從網上搜了乙個能夠自動關閉的提示框 ,但由於我需要的場景是不確定計時時間的,所以並沒有使用到該窗體,但是我覺得可以留存備用 ,後邊也把我這種倒計時的提示框用處還是很多的,用於自動彈窗 自動關閉 ,雖然在我的專案中沒有

其核心方法在timer(timercallback,object,int32,int32) timercallback是乙個委託 ,代表要執行的方法,其用途可以用在各個定時去呼叫方法的場景,而且可以設定窗體的formborderstyle的屬性為none,設定窗體邊框和標題欄外觀不顯示.

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

pu程式設計客棧blic void getmassage(string text)

public void gettext(string caption)

system.threading.timer _timeouttimer;

string _caption;

autoclosemessagebox(string text, string caption, int timeout)

void ontimerelapsed(object state)

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.interop程式設計客棧services.charset.auto)]

static extern intptr sendmessage(intptr hwnd, uint32 msg, intptr wparam, intptr lparam);

}}呼叫時直接使用類名.show(text,captiom,timeout)直接呼叫即可

下邊是當時的專案使用場景的解決辦法

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

private void barcodeerrorform_load(object sender, eventargs e)

public void clear()

else

}public void setmsg(string msg)

else

}public point point1

public void showform()

else

}public void hideform()

else}}}

該窗體可以用於實時監控某乙個狀態時 而彈出的提示框 並根據狀態改變而隱藏

使用時,new乙個該errorform

在該窗體有乙個richtextbox,用來顯示提示資訊,使用setmsg,設定要顯示的資訊

需要彈出時,例項呼叫show(程式設計客棧)方法  實際就是講該窗體的visible屬性置為true,讓窗體顯示,並且呼叫clear方法,清除提示資訊

需要隱藏時,例項呼叫hideform()方法,將窗體visible屬性設定為false,呼叫clear方法,清除提示資訊

總結本文標題: c#實現倒計時關閉提示框功能

本文位址:

實現倒計時功能

一 php time1 strtotime date y m d h i s time2 strtotime 2017 01 01 00 00 00 time3 strtotime 2017 05 01 sub1 ceil time2 time1 3600 60 60 sub2 ceil time3...

Lua 實現倒計時功能

lua 實現倒計時功能 local size ccdirector shareddirector getwinsize local scheduler ccdirector shareddirector getscheduler local run logic nil 時 分 秒 數值 local ...

Unity實現倒計時功能

有兩種思路可以實現倒計時,乙個是update,另乙個是協程。這裡只展示核心的演算法思路,有收穫的還請點個贊哦 update 首先定義三個變數,訪問許可權按需求設定 float gametime 遊戲總時間,int或者float都可,單位為秒 float timeleft 遊戲剩餘時間,單位為秒 fl...