七夕了。。。送祝福了。。。鲜花屏显,跑马灯。。
部分代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ChineseValentinesDay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 0;
//int j = 0;
public int FormHeight
{
get;
set;
}
public int FormWidth
{
get;
set;
}
PictureBox[] pbArray;
SoundPlayer sp = new SoundPlayer();
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = Color.White;//设置窗体的背景效果为无色
FormHeight = this.ClientSize.Height;
FormWidth = this.ClientSize.Width;
pbArray = new PictureBox[] {
pictureBox1,pictureBox2,pictureBox3,pictureBox4,pictureBox5,pictureBox6,
pictureBox7,pictureBox8,pictureBox9,pictureBox10,pictureBox11,pictureBox12,
pictureBox13,pictureBox14,pictureBox15,pictureBox16,pictureBox17,pictureBox18
};
sp.SoundLocation = @"..\..\sounds\LoveYou.wav";
//sp.Play();
sp.PlayLooping();//循环播放
}
string[] filePathArray = Directory.GetFiles("..\\..\\images", "*.jpg");
Random r = new Random();
List<int> listInt = new List<int>();
private void timer1_Tick(object sender, EventArgs e)
{
int num = labWish.Text.Length;
labWish.Text = labWish.Text.Substring(1, num - 1) +
labWish.Text.Substring(0, 1);
if(i>17) //18个pictureBox
{
i = 0;
}
else
{
//while(true)
//{
i = r.Next(0, 18);//产生0-17的随机数
listInt.Add(i);
//if(listInt.Contains(i))
//{
// continue;
//}
//else
//{
pbArray[i].SizeMode = PictureBoxSizeMode.Zoom;
pbArray[i].BackColor = Color.Transparent;
//pbArray[i].Location = new Point(iwidth, iheight);//设定pictureBox控件的位置
string fileName = r.Next(1, 35).ToString() + ".jpg";//
pbArray[i].ImageLocation = "..\\..\\images\\" + fileName;//相对路径
i++;
//}
//}
}
}
}
}
效果: