90坦克第三集


/****************************************计时器的代码测试**************************************************/
/****************************************图形界面测试代码**************************************************/
/****************************************滑块移动,引入键盘事件********************************************/
// 因为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();
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值