我把我的代码发出来吧:
登录框代码:
public partial class TanChuKuang : Form
{
public TanChuKuang()
{
InitializeComponent();
}
private void TanChuKuang_Load(object sender, EventArgs e)
{
Button btjin = new Button();
//进入按钮。
btjin.Location = new Point(133, 63);
btjin.Size = new Size(75, 23);
btjin.Text = "进 入";
btjin.Click += new EventHandler(btjin_Click);
this.Controls.Add(btjin);
}
//在弹出这个消息框之前先显示主窗体,但不加载主窗体中的按钮,然后显示这个消息框,点击进入关闭消息框加载主窗体按钮。
private void btjin_Click(object sender, EventArgs e)
{
}
}
主窗体代码:
public partial class Form1 : Form
{
SoundPlayer spshu = new SoundPlayer("慢.wav");
Timer tmshan = new Timer();
PictureBox[] pbtu = new PictureBox[10];
int ci = 0;
int dianji = 0;
public Form1()
{
TanChuKuang tan = new TanChuKuang();
//实例化弹出窗体
InitializeComponent();
tan.ShowDialog();
//弹出窗体
}
private void Form1_Load(object sender, EventArgs e)
{
int tuX = 13, tuY = 73, tusizeX = 30, tusizeY = 46;
//图片控件的位置
for (int i = 0; i < pbtu.Length; i++,tuX+=58)
//实例化图片控件
{
pbtu[i] = new PictureBox();
pbtu[i].Location = new Point(tuX, tuY);
pbtu[i].Size = new Size(tusizeX, tusizeY);
pbtu[i].BackColor = Color.Black;
this.Controls.Add(pbtu[i]);
}
Button btshan = new Button();
//闪烁按钮。
btshan.Location = new Point(213,176);
btshan.Size = new Size(75,23);
btshan.Text = "闪 烁";
btshan.Click+=new EventHandler(btshan_Click);
this.Controls.Add(btshan);
tmshan.Tick+=new EventHandler(tmshan_Tick);
//定时器时间到事件。
}
private void btshan_Click(object sender, EventArgs e)
{
if (dianji == 0)
{
dianji = 1;
ci = 0;
tmshan.Interval = 500;
tmshan.Start();
}
}
private void tmshan_Tick(object sender, EventArgs e)
{
if (ci - 1 == -1)
pbtu[9].Image = null;
else if (pbtu[(ci - 1) % 10].Image != null)
pbtu[(ci - 1) % 10].Image = null;
pbtu[ci%10].Image = imageNumber.Images[ci%10];
if (ci == 5)
{
spshu.Play();
tmshan.Interval = 270;
}
else if (ci == 6)
{
tmshan.Interval = 290;
}
else if (ci == 7)
{
tmshan.Interval = 380;
}
else if (ci == 8)
{
tmshan.Interval = 560;
}
else if (ci == 9)
{
dianji = 0;
tmshan.Stop();
}
ci++;
}
}