winform第二天

1、Directory 操作文件夹
CreateDirectory 创建文件夹
Delete 删除文件夹
Move 剪切文件夹
GetFiles 获得指定的目录下所有文件的全路径
GetDirectory 获得指定目录下所有文件夹的全路径


2、WebBrowser浏览器控件
url

3、ComboBox下拉框控件
DropDownstyle:控制下拉框的外观样式

4、心算闯关。
核心业务代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form8 : Form
    {
        public Form8()
        {
            InitializeComponent();
        }
        private void Form8_Load(object sender, EventArgs e)
        {
            AllVisible();
        }

        public void AllVisible() {
            IblNum1.Visible = false;
            IblDo.Visible = false;
            IblNum2.Visible = false;
            IblTo.Visible = false;
            IblNum3.Visible = false;
            IblTips.Visible = false;
            IblTimeShow.Visible = false;
            IblTimeNumber.Visible = false;
            IblLifeShow.Visible = false;
            IblLifeNumber.Visible = false;
            IblAnswer.Visible = false;
            TxtAnswer.Visible = false;
        }
        float CountNumber;
        int Score = 0;//分数
        int LifeNumber = 0;//生命值
        private void BtnStarOrsub_Click(object sender, EventArgs e)
        {
            IblNum1.Visible = true;
            IblDo.Visible = true;
            IblNum2.Visible = true;
            IblTo.Visible = true;
            IblNum3.Visible = true;
            IblTips.Visible = true;
            IblTimeShow.Visible = true;
            IblTimeNumber.Visible = true;
            IblLifeShow.Visible = true;
            IblLifeNumber.Visible = true;
            IblAnswer.Visible = true;
            TxtAnswer.Visible = true;
            string Text = TxtAnswer.Text;
            Console.WriteLine(Text);
            if (BtnStarOrsub.Text == "开始游戏")
            {
                BtnStarOrsub.Text = "提交答案";
                AllUpdate();
            }
            if (TxtAnswer.Text == "")
            {
                return;
            }
            if (TxtAnswer.Text == CountNumber.ToString())
            {
                MessageBox.Show("恭喜你答对了");
                TxtAnswer.Clear();
                AllUpdate();
                Score++;
            }
            else
            {
                MessageBox.Show("你答错了");
                TxtAnswer.Clear();
                AllUpdate();
                LifeNumber = Convert.ToInt32(IblLifeNumber.Text);
                LifeNumber--;
                IblLifeNumber.Text = LifeNumber.ToString();
                if (LifeNumber == 0)
                {
                    MessageBox.Show("游戏结束,你本次得分:{0}", Score.ToString());
                    AllVisible();
                    BtnStarOrsub.Text = "游戏开始";
                }

            }
        }
            public void AllUpdate() {
                int Num1 = RandomNum(0, 101);
                Thread.Sleep(200);
                int Num2 = RandomNum(0, 101);

                int caozuo = RandomNum(0, 4);

                CountNumber = Count(Num1, Num2, caozuo);//四则运算结果

                IblNum1.Text = Num1.ToString();
                IblNum2.Text = Num2.ToString();
           
            }
            public float Count(int a, int b, int caozuo) {
                float count = 0F;
                switch (caozuo)
                {
                    case 0: count = a + b;IblDo.Text = "+"; break;
                    case 1: count = a - b; IblDo.Text = "-"; break;
                    case 2: count = a * b; IblDo.Text = "*"; break;
                    case 3: count = a / b; IblDo.Text = "/"; break;
                    default:
                        break;
                }
                return count;
            }
            public int RandomNum(int a, int b) {
                Random r = new Random();
                return r.Next(a, b);
            }

        }
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值