程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 用ASP.NET實現一個簡單的計算器(適合入門者)

用ASP.NET實現一個簡單的計算器(適合入門者)

編輯:.NET實例教程

文件:
Calculate.ASPx
bin/Calculate.cs
bin/Calculate.bat

步驟:
1.Calculate.cs

namespace Calculate
{
using System;
public class math {

public String _color;
public int Add(int a,int b)
{
return a+b;
}

public int Sub(int a,int b)
{
return a-b;
}

public int Mul(int a,int b)
{
return a*b;
}
public String Color
{
get {
return _color;
}
set {
_color=value;
}
}

}
}

2.Calculate.bat

csc /t:library /out:Calculate.dll Calculate.cs

3.執行Calculate.bat

4.Calculate.ASPx


<%@Import NameSpace="Calculate"%>

<script language="c#" runat="server">
public String color;
void DoAdd(Object Src, EventArgs E)
{
math math=new math();
Message.Text=math.Add(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();
math.Color=C.Value;
color=math.Color;

}

void DOSub(Object Src, EventArgs E)
{
math math=new math();
Message.Text=math.Sub(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();
math.Color=C.Value;
color=math.Color;
}

void DoMul(Object Src, EventArgs E)
{
math math=new math();
Message.Text=math.Mul(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();
math.Color=C.Value;
color=math.Color;

}

</script>
<font id=Cau color=<%Response.Write(color);%>>用ASP+寫得簡易計算器</font>
<form runat="server">

<input id="A" runat="server"/>
<input id="B" runat="server"/>
<input id="C" runat="server"/>
<ASP:button Text="Add" OnClick="DoAdd" runat="server"/>
<ASP:button Text="Sub" OnClick="DOSub" runat="server"/>
<ASP:button Text="Mul" OnClick="DoMul" runat="server"/>
</form>
Result:<ASP:label id=Message runat="server"/>

文件:
Calculate.ASPx
bin/Calculate.cs
bin/Calculate.bat

步驟:
1.Calculate.cs

namespace Calculate
{
using System;
public class math {

public String _color;
public int Add(int a,int b)
{
return a+b;
}

public int Sub(int a,int b)
{
return a-b;
}

public int Mul(int a,int b)
{
return a*b;
}
public String Color
{
get {
return _color;
}
set {
_color=value;
}
}

}
}

2.Calculate.bat

csc /t:library /out:Calculate.dll Calculate.cs

3.執行Calculate.bat

4.Calculate.ASPx


<%@Import NameSpace="Calculate"%>

<script language="c#" runat="server">
public String color;
void DoAdd(Object Src, EventArgs E)
{
math math=new math();
Message.Text=math.Add(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();
math.Color=C.Value;
color=math.Color;

}

void DOSub(Object Src, EventArgs E)
{
math math=new math();
Message.Text=math.Sub(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();
math.Color=C.Value;
color=math.Color;
}

void DoMul(Object Src, EventArgs E)
{
math math=new math();
Message.Text=math.Mul(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();
math.Color=C.Value;
color=math.Color;

}

</script>
<font id=Cau color=<%Response.Write(color);%>>用ASP+寫得簡易計算器</font>
<form runat="server">

<input id="A" runat="server"/>
<input id="B" runat="server"/>
<input id="C" runat="server"/>
<ASP:button Text="Add" OnClick="DoAdd" runat="server"/>
<ASP:button Text="Sub" OnClick="DOSub" runat="server"/>
<ASP:button Text="Mul" OnClick="DoMul" runat="server"/>
</form>
Result:<ASP:label id=Message runat="server"/>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved