第三篇 一個屏幕開滿玫瑰花的程序


思路:窗體全屏且透明,在窗體中隨機繪制圖片、

代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Rose.net3.Properties;
using System.Windows.Forms.VisualStyles;

namespace Rose.net3
{
public partial class Form1 : Form
{
private static readonly int WIDTH = Screen.PrimaryScreen.WorkingArea.Width;
private static readonly int HEIGHT = Screen.PrimaryScreen.WorkingArea.Height;
private static int i = 0;
Timer timer = new Timer();
private Random random = new Random();
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.Width = WIDTH;
this.Height = HEIGHT;
this.TransparencyKey = this.BackColor;
this.StartPosition = FormStartPosition.CenterScreen;
this.Location=new Point(1,1);

timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 100;
timer.Start();
}

void timer_Tick(object sender, EventArgs e)
{
i++;
int x = random.Next(-10, WIDTH - 100);
int y = random.Next(-10, HEIGHT - 100);
Graphics gr;
gr = CreateGraphics();
gr.DrawImage(Resources.Rose,new Point(x,y));
if (i == 100)
{
timer.Stop();
}
}



private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode== Keys.Escape)
{
this.Close();
}
}
}
}



注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com