/****************************************计时器的代码测试**************************************************/
/****************************************图形界面测试代码**************************************************/
/****************************************滑块移动,引入键盘事件********************************************/
// 因为C#中只有极少部分代码是直接使用的,多数代码需要引入类的名字才可以使用里面的代码。
// 引入System包,可以使用Console.WriteLine这句代码
using System;
// 引入System.Threading包,可以使Timer类和TimerCallback类
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
// C#需要这个namespace照着写就行,game是namespace的名字,随便取,这行就照抄就行,没有大问题
namespace game
{
// 这是一个大功能块,大功能块的名字叫test
public class test
{
static int n = 0;
static Label l = new Label();
static Form f = new Form();
static int len = 0;
public static void TimerUp(object o){
int left = l.Left;
int top = l.Top;
if(len<50){
len++;
left++;
l.Left = left;
}
//Console.WriteLine("nnn343=" + n);
}
//这是功能块中细化下来的功能块,叫test2
public static void test2(){
// 这句话很长,只有四个东西要记一下,其它照着写就行,
// 分别是TimeUp,3000,1000,500
// TimeUp
new System.Threading.Timer(new TimerCallback(TimerUp), null, 3000, 1000).Change(0,3);
}
public static void test4(){
new Thread(delegate(){
f.KeyPress += new KeyPressEventHandler(keypressed);
}).Start();
}
private static void keypressed(Object o, KeyPressEventArgs e) {
Console.Write(e.KeyChar);
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
}
}
static void Main(string[] args)
{
test2();
test3();
test4();
Console.Read();
}
public static void test3(){
new Thread(delegate(){
f.Height = 600;
f.Width = 1000;
f.Location = new Point(400,300);
f.Show();
f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
l.Height = 50;
l.Width = 50;
l.Top = 300;
l.Left = 500;
l.Text = "ddd";
l.BackColor = Color.Black;
f.Controls.Add(l);
Application.Run(f);
}).Start();
}
}
}