想法:將屏幕截圖作為程序背景圖,在之上彈出提示窗口,選擇確定後進行定時圖片隨機位置顯示。(支持ESC鍵退出)
1 Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty)); 2 3 public Form1() 4 { 5 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 6 this.BackgroundImage = GetNoCursor(); 7 InitializeComponent(); 8 } 9 10 private void Form1_Load(object sender, EventArgs e) 11 { 12 timer1.Interval = 500; 13 if (MessageBox.Show("消息", "標題", MessageBoxButtons.YesNo) == DialogResult.Yes) 14 { 15 timer1.Enabled = true; 16 } 17 else 18 { 19 this.Close(); 20 } 21 } 22 23 private void Form1_KeyDown(object sender, KeyEventArgs e) 24 { 25 if (e.KeyData == Keys.Escape) 26 { 27 timer1.Enabled = false; 28 MessageBox.Show("消息", "標題", MessageBoxButtons.OK); 29 this.Close(); 30 } 31 } 32 33 private Bitmap GetNoCursor() 34 { 35 Bitmap Source = new Bitmap(bounds.Width, bounds.Height); //根據屏幕大小創建Bitmap對象 36 Graphics g = Graphics.FromImage(Source); 37 g.CopyFromScreen(0, 0, 0, 0, Source.Size); //獲取沒有鼠標的屏幕截圖 38 g.Dispose(); //釋放資源 39 return Source; 40 } 41 42 private void timer1_Tick(object sender, EventArgs e) 43 { 44 Image img = Resource1.Image1;//獲取用於顯示的資源文件 45 if (img != null) 46 { 47 Graphics g = this.CreateGraphics(); 48 Random rd = new Random(); 49 int picXPoint = rd.Next(0, bounds.Right - img.Width); 50 int picYPoint = rd.Next(0, bounds.Height - img.Height); 51 Point ulCorner = new Point(picXPoint, picYPoint); 52 g.DrawImageUnscaled(img, ulCorner); 53 } 54 else 55 { 56 timer1.Enabled = false; 57 MessageBox.Show("沒有圖片,感謝使用"); 58 this.Close(); 59 } 60 }