最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C#教学经验谈(2):会跑的按钮
时间:2022-07-02 11:09:32 编辑:袖梨 来源:一聚教程网
为了让学生对事件有一个初步的印象,特意设计了一个趣味程序,界面较简单,就是提一个简单的问题,要你点Yes或No按钮来回答问题。但当你去点Yes按钮的时候,这个Yes按钮会满窗口的跑,不让你去点它。
这个趣味程序是在教学过程中临时穿插进去的。使用这个程序的目的,是让学生对C#中对事件的处理有一个初步的印象,了解事件要经过注册和实现这两步,另外通过这个趣味程序,让学生了解Random类和Point类的使用。
本程序的全部代码如下,请注意红字的代码,其余的代码都是设计器自动生成的。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace LoveMe
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button yesButton;
private System.Windows.Forms.Button noButton;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
这个趣味程序是在教学过程中临时穿插进去的。使用这个程序的目的,是让学生对C#中对事件的处理有一个初步的印象,了解事件要经过注册和实现这两步,另外通过这个趣味程序,让学生了解Random类和Point类的使用。
本程序的全部代码如下,请注意红字的代码,其余的代码都是设计器自动生成的。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace LoveMe
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button yesButton;
private System.Windows.Forms.Button noButton;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
相关文章
- Canvas如何做个雪花屏版404的实现 07-03
- 炉石传说安戈洛龟途乱斗任务瞎卡组推荐 07-03
- 解限机天袭者地图适配性汇总 07-03
- 币圈:Grok AI 怎么下载? Grok 3 功能亮点与主流 AI 工具比较(2025 最新)? 07-03
- 柴犬币负责人表示七月将有大动作,预告多项公告即将发布 07-03
- 死亡搁浅2次要订单116支线任务完成方法 07-03