在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
(1)首先新建一个类库项目,命名为MessageNotify。
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; namespace KoalaStudio.ModuleLibrary { internal partial class MessageNotifyForm : Form { //提示框高度 private int _HeightMax; /// 提示框高度 public int HeightMax { set { _HeightMax = value; } } /// 提示框停留时间(单位:秒) public int StayTime { set { this.TimerStay.Interval = value ; } } /// 显示窗体 public void ShowMessage(string text) { this.lblContent.Text = text; this.TimerUp.Enabled = true; this.Height = 0; this.Show(); } /// 显示窗体 public void ShowMessage(string text, string caption) { this.Text = caption ; this.lblContent.Text = text; this.TimerUp.Enabled = true; this.Height = 0; this.Show(); } /// 向上移动窗体 private void MoveUp() { if (this.Height < _HeightMax) { this.Height += 3; this.Location = new Point(Location.X, Location.Y - 3); } else { this.TimerUp.Enabled = false; this.TimerStay.Enabled = true; } } /// 向下移动窗体 private void MoveDown() { if (this.Height > 0) { this.Height -= 3; this.Location = new Point(Location.X, Location.Y + 3); } else { this.TimerDown.Enabled = false; this.Close(); } } public MessageNotifyForm() { InitializeComponent(); } private void MessageNotify_Load(object sender, EventArgs e) { //根据不同的屏幕分辨率来确定窗体的初始位置 Screen[] screens = Screen.AllScreens; Screen screen = screens[0]; this.Location = new Point(screen.WorkingArea.Width - this.Width - 2, screen.WorkingArea.Height - 30); } private void TimerUp_Tick(object sender, EventArgs e) { this.MoveUp(); } private void TimerStay_Tick(object sender, EventArgs e) { this.TimerStay.Enabled = false; this.TimerDown.Enabled = true; } private void TimerDown_Tick(object sender, EventArgs e) { this.MoveDown(); } } }
(4)添加一个类文件,命名为MessageNotify,代码如下:
using System;
using System.Collections.Generic; using System.Text; namespace KoalaStudio.ModuleLibrary { public class MessageNotify { //当前显示的提示框的数量 private static int _Count = 0; //提示框宽度 private static int _WidthMax = 180; //提示框高度 private static int _HeightMax = 120; //提示框停留时间(单位:毫秒) private static int _StayTime = 5000; /// 提示框宽度 public static int WidthMax { set { _WidthMax = value; } get { return _WidthMax; } } /// 提示框高度 public static int HeightMax { set { _HeightMax = value; } get { return _HeightMax; } } /// 提示框停留时间(单位:秒) public static int StayTime { set { _StayTime = value; } get { return _StayTime / 1000; } } public static void Show(string text) { MessageNotifyForm messageNotifyForm = new MessageNotifyForm(); messageNotifyForm.Width = _WidthMax; messageNotifyForm.HeightMax = _HeightMax; messageNotifyForm.StayTime = _StayTime; messageNotifyForm.ShowMessage(text); } public static void Show(string text, string caption) { MessageNotifyForm messageNotifyForm = new MessageNotifyForm(); messageNotifyForm.Width = _WidthMax; messageNotifyForm.HeightMax = _HeightMax; messageNotifyForm.StayTime = _StayTime; messageNotifyForm.ShowMessage(text, caption); } } }
(5)将项目生成为dll文件,在应用中引用后即可直接调用,格式如下:
|
请发表评论