/*
*程序的版权和版本声明部分:
*程序的版权和版本声明部分:
*Copyright(c)2013,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:尚振伟
*完成日期:2014年11月12日
*版本号:v0.1
*对任务及求解方法的描述部分:
*输入描述:无
*问题描述:
*程序输入:
*程序输出:
*问题分析:
*算法设计:
*我的程序:
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Random rd = new Random();
label4.Text= rd.Next(10,99).ToString();
label4.Visible = false;
}
void Guess(int result, int guessResult)
{
if (guessResult < result)
{
label2.Text = "猜小了";
}
else if (guessResult > result)
{
label2.Text = "猜大了";
}
else
{
label4.Visible = true;
label2.Text = "猜对了";
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Guess(int.Parse(label4.Text), int.Parse(textBox1.Text));
textBox1.Clear();
textBox1.Focus();
}
}
}
}
结果展示:
心得体会:这次的是猜对才显示谜底。