WinForm 类QQ消息提示窗
做一个简单的类似QQ的消息提示窗体,提示消息之后在指定的时间内自动关闭,或通过点击关闭按钮关闭。
在VS2005建立一个WINDOWS应用程序,添加一个窗体,名字就用barForm,FormBorderStyle设为None;
BackgroundImage就用一个带关闭图标的背景,关闭图标大小为10*10;
窗体中放两个Label,Label1用于显示传递的信息,Label2用来显示实时时间;
设置两个定时器,timer1用来触发关闭消息提示窗体,其Interval设置为1000;
timer2用来刷时间,其Interval设置为1000!
代码部分如下:
引用:
using System.Runtime.InteropServices;
using System.Windows.Forms;
public partial class barForm : Form
{
public const Int32 AW_HOR_POSITIVE = 0x00000001;//从左到右打开窗口 
public const Int32 AW_HOR_NEGATIVE = 0x00000002;//从右到左打开窗口
public const Int32 AW_VER_POSITIVE = 0x00000004;//从上到下打开窗口
qq消息
重阳节手抄报内容文字public const Int32 AW_VER_NEGATIVE = 0x00000008;//从下到上打开窗口
public const Int32 AW_CENTER = 0x00000010;
public const Int32 AW_HIDE = 0x00010000;
冒险岛任务
public const Int32 AW_ACTIVATE = 0x00020000;//在窗体打开后不失去焦点
public const Int32 AW_SLIDE = 0x00040000;
public const Int32 AW_BLEND = 0x00080000;//淡入淡出效果
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
private string information=null;//要在窗体中显示的信息
public barForm(string info)
{
InitializeComponent();
information = info;
this.timer2.Enabled = true;//启动时间
}
private void TaskbarForm_Load(object sender, EventArgs e)
完全竞争市场{
try
{
int x = Screen.PrimaryScreen.WorkingArea.Size.Width - this.Width;
int y = Screen.PrimaryScreen.WorkingArea.Size.Height - this.Height;
this.SetDesktopLocation(x, y);
this.Label1.Text = information;
AnimateWindow(this.Handle, 1000, AW_VER_NEGATIVE | AW_ACTIVATE);//从下到上且不占其它程序焦点
this.timer1.Enabled = true;
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
int count = 0;//计数器
private void timer1_Tick(object sender, EventArgs e)
{
count++;
if (count == 50)//5s关闭提示窗体
{
count = 0;
AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE);
this.Close();
}
}
private void timer2_Tick(object sender, EventArgs e)
{
this.Label2.Text = DateTime.Now.ToString("F");
}
private void barForm_MouseClick(
object sender, MouseEventArgs e)
{
if (e.Button = MouseButtons.Left)//左键点击
{
if (Screen.PrimaryScreen.WorkingArea.Size.Width - e.X < 10 &&农业生产类型
Screen.PrimaryScreen.WorkingArea.Size.Height - e.Y < 10)//有效范围判断
{
AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE);
this.Close();
}
}
}
在其他代码中的调用示例:
string info="hello world!";
barForm form = new barForm(info);
西葫芦饼form.Show();

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。