嘿嘿,先说下要求
我创建一个窗口,然后窗口上出现几个字,比如 GAME OVER,能显示汉字更好GAME OVER 从窗口的左边往右边移动,移动到底的时候,GAME OVER消失,又在中间显示GAME OVER没有鼠标点击等触发事件,程序启动后就直接运行大侠们,给个代码吧,这对我很重要
我创建一个窗口,然后窗口上出现几个字,比如 GAME OVER,能显示汉字更好GAME OVER 从窗口的左边往右边移动,移动到底的时候,GAME OVER消失,又在中间显示GAME OVER没有鼠标点击等触发事件,程序启动后就直接运行大侠们,给个代码吧,这对我很重要
当label.Left < 窗体width的时候,设置到中间位置。然后停止timer.
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private string _displaytext = "GAME OVER";
private Font _font = new Font(new FontFamily("Arial Unicode MS"), 30, FontStyle.Bold);
private Brush _textcolor = Brushes.Red;
private int _sleep = 40;
private int _skippx = 3;
private SizeF _textsize = Size.Empty; private Image DrawText(int x, int y, int width, int height, Color background)
{
Bitmap b = new Bitmap(width, height);
Graphics g = Graphics.FromImage(b);
g.Clear(background); if (_textsize.IsEmpty)
{
_textsize = g.MeasureString(_displaytext, _font);
} g.DrawString(_displaytext, _font, _textcolor, (float)x, (float)y);
g.Save();
g.Dispose();
return b;
} private delegate Size D_GetControlSize(Control c);
private delegate Color D_GetControlBackGroundColor(Control c);
private delegate void D_SetFormBackImage(Form f, Image img); private Size GetControlSize(Control c)
{
return c.Size;
} private Color GetControlBackGroundColor(Control c)
{
return c.BackColor;
} private void SetFormBackImage(Form f, Image img)
{
f.BackgroundImage = img;
} private void PlayText(object frm)
{
if (frm == null || !(frm is Form))
return;
Form f = (Form)frm; Size size = (Size)f.Invoke(new D_GetControlSize(GetControlSize), f);
Color backcolor = (Color)f.Invoke(new D_GetControlBackGroundColor(GetControlBackGroundColor), f); D_SetFormBackImage setImage = new D_SetFormBackImage(SetFormBackImage); for (int i = 0; i < size.Width; i += _skippx)
{
f.Invoke(setImage, f, DrawText(i, (size.Height - (int)_textsize.Height) / 2, size.Width, size.Height, backcolor));
Thread.Sleep(_sleep);
} f.Invoke(setImage, f, DrawText((size.Width - (int)_textsize.Width) / 2, (size.Height - (int)_textsize.Height) / 2, size.Width, size.Height, backcolor)); } private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ParameterizedThreadStart(PlayText));
t.Start(this);
}
}
}
我无聊之下给你写的代码无法完全满足您的要求真是对不起了,我错了,浪费了你时间。