国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#教學經驗談(2):會跑的按鈕

2024-07-21 02:18:06
字體:
來源:轉載
供稿:網友
為了讓學生對事件有一個初步的印象,特意設計了一個趣味程序,界面較簡單,就是提一個簡單的問題,要你點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
{
/// <summary>
/// form1 的摘要說明。
/// </summary>
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;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private system.componentmodel.container components = null;

public form1()
{
//
// windows 窗體設計器支持所必需的
//
initializecomponent();

//
// todo: 在 initializecomponent 調用后添加任何構造函數代碼
//
}

/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void initializecomponent()
{
this.label1 = new system.windows.forms.label();
this.yesbutton = new system.windows.forms.button();
this.nobutton = new system.windows.forms.button();
this.suspendlayout();
//
// label1
//
this.label1.font = new system.drawing.font("monotype corsiva", 36f, system.drawing.fontstyle.italic, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.label1.forecolor = system.drawing.color.forestgreen;
this.label1.location = new system.drawing.point(40, 72);
this.label1.name = "label1";
this.label1.size = new system.drawing.size(320, 80);
this.label1.tabindex = 0;
this.label1.text = "do you love me?";
//
// yesbutton
//
this.yesbutton.location = new system.drawing.point(56, 248);
this.yesbutton.name = "yesbutton";
this.yesbutton.tabindex = 1;
this.yesbutton.text = "yes";
this.yesbutton.click += new system.eventhandler(this.yesbutton_click);
this.yesbutton.mousemove += new system.windows.forms.mouseeventhandler(this.yesbutton_mousemove);
//
// nobutton
//
this.nobutton.location = new system.drawing.point(240, 248);
this.nobutton.name = "nobutton";
this.nobutton.tabindex = 1;
this.nobutton.text = "no";
this.nobutton.click += new system.eventhandler(this.nobutton_click);
//
// form1
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(400, 317);
this.controls.add(this.yesbutton);
this.controls.add(this.label1);
this.controls.add(this.nobutton);
this.name = "form1";
this.text = "想說愛我不容易";
this.resumelayout(false);

}
#endregion

/// <summary>
/// 應用程序的主入口點。
/// </summary>
[stathread]
static void main()
{
application.run(new form1());
}

private void nobutton_click(object sender, system.eventargs e)
{
messagebox.show("oh,bye-bye!","i'm sorry",messageboxbuttons.ok,messageboxicon.warning);
this.close();
}

private void yesbutton_click(object sender, system.eventargs e)
{
messagebox.show("thank you, i'm very happy!","happy",messageboxbuttons.ok,messageboxicon.information);
}
private void yesbutton_mousemove(object sender, system.windows.forms.mouseeventargs e)
{
random rand = new random(unchecked((int)datetime.now.ticks));
int x=rand.next(0,this.size.width-100);
int y=rand.next(0,this.size.height-50);
point point=new point(x,y);
yesbutton.location=point;
}

}
}




發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 铜川市| 双牌县| 高陵县| 威信县| 武功县| 综艺| 乌恰县| 汉川市| 花莲县| 胶州市| 柳州市| 甘孜县| 平昌县| 瑞金市| 长泰县| 阿坝县| 崇文区| 鲁甸县| 邢台市| 新疆| 洛浦县| 米易县| 滦南县| 桓台县| 宝丰县| 醴陵市| 文山县| 桃江县| 泰安市| 固原市| 巍山| 台南市| 独山县| 广汉市| 涿州市| 临江市| 井冈山市| 霍城县| 双桥区| 资阳市| 儋州市|