schangxiang@126.com
2025-09-04 9fcc7df37205632d94665af7fc7ea56650e79789
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WMS.UI.Basic
{
    public partial class messages : Form
    {
 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
        /// <summary>
        /// 得到当前活动的窗口
        /// </summary>
        /// <returns></returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern System.IntPtr GetForegroundWindow();
        public messages(int type,string text)
        {
            InitializeComponent();
           
            this.Location=new Point( Screen.GetWorkingArea(this).Width/2-this.Width/2, 50);
            if (type == 1)
            {
                this.BackColor = Color.FromArgb(240, 249, 235);
                label1.ForeColor = Color.FromArgb(103, 194, 109);
                label1.Text = text;
            }
            else
            {
                this.BackColor = Color.FromArgb(254, 240, 240);
                label1.ForeColor = Color.FromArgb(245, 108, 108);
                label1.Text = text;
            }
            SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);
        }
 
      
 
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            for (int i = 0; i <= this.Height; i++)
            {
                Point p = new Point(this.Location.X, Location.Y -i);
                this.PointToScreen(p);
                this.Location = p;
                System.Threading.Thread.Sleep(10);
            }
            this.Close();
        }
    }
}