html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

用ASP.NET实现一个简单的计算器_.NET教程_编程技术

[ ] 已经帮助:人解决问题
asp.net


文件:
Calculate.aspx
bin/Calculate.cs
bin/Calculate.batqk3HTML5中文学习网 - HTML5先行者学习网

步骤:
1.Calculate.csqk3HTML5中文学习网 - HTML5先行者学习网

namespace Calculate
{
using System;
public class math {qk3HTML5中文学习网 - HTML5先行者学习网

public String _color;
public int Add(int a,int b)
{
return a+b;
}qk3HTML5中文学习网 - HTML5先行者学习网

public int Sub(int a,int b)
{
return a-b;
}qk3HTML5中文学习网 - HTML5先行者学习网

public int Mul(int a,int b)
{
return a*b;
}
public String Color
{
get {
return _color;
}
set {
_color=value;
}
}qk3HTML5中文学习网 - HTML5先行者学习网

}
}qk3HTML5中文学习网 - HTML5先行者学习网

2.Calculate.batqk3HTML5中文学习网 - HTML5先行者学习网

csc /t:library /out:Calculate.dll Calculate.csqk3HTML5中文学习网 - HTML5先行者学习网

3.执行Calculate.batqk3HTML5中文学习网 - HTML5先行者学习网

4.Calculate.aspx
qk3HTML5中文学习网 - HTML5先行者学习网

<%@Import NameSpace="Calculate"%>qk3HTML5中文学习网 - HTML5先行者学习网

<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;qk3HTML5中文学习网 - HTML5先行者学习网

}qk3HTML5中文学习网 - HTML5先行者学习网

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;
}qk3HTML5中文学习网 - HTML5先行者学习网

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;qk3HTML5中文学习网 - HTML5先行者学习网

}qk3HTML5中文学习网 - HTML5先行者学习网

</script>
<font id=Cau color=<%Response.Write(color);%>>用ASP+写得简易计算器</font>
<form runat="server">qk3HTML5中文学习网 - HTML5先行者学习网

<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"/>qk3HTML5中文学习网 - HTML5先行者学习网

文件:
Calculate.aspx
bin/Calculate.cs
bin/Calculate.batqk3HTML5中文学习网 - HTML5先行者学习网

步骤:
1.Calculate.csqk3HTML5中文学习网 - HTML5先行者学习网

namespace Calculate
{
using System;
public class math {qk3HTML5中文学习网 - HTML5先行者学习网

public String _color;
public int Add(int a,int b)
{
return a+b;
}qk3HTML5中文学习网 - HTML5先行者学习网

public int Sub(int a,int b)
{
return a-b;
}qk3HTML5中文学习网 - HTML5先行者学习网

public int Mul(int a,int b)
{
return a*b;
}
public String Color
{
get {
return _color;
}
set {
_color=value;
}
}qk3HTML5中文学习网 - HTML5先行者学习网

}
}qk3HTML5中文学习网 - HTML5先行者学习网

2.Calculate.batqk3HTML5中文学习网 - HTML5先行者学习网

csc /t:library /out:Calculate.dll Calculate.csqk3HTML5中文学习网 - HTML5先行者学习网

3.执行Calculate.batqk3HTML5中文学习网 - HTML5先行者学习网

4.Calculate.aspx
qk3HTML5中文学习网 - HTML5先行者学习网

<%@Import NameSpace="Calculate"%>qk3HTML5中文学习网 - HTML5先行者学习网

<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;qk3HTML5中文学习网 - HTML5先行者学习网

}qk3HTML5中文学习网 - HTML5先行者学习网

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;
}qk3HTML5中文学习网 - HTML5先行者学习网

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;qk3HTML5中文学习网 - HTML5先行者学习网

}qk3HTML5中文学习网 - HTML5先行者学习网

</script>
<font id=Cau color=<%Response.Write(color);%>>用ASP+写得简易计算器</font>
<form runat="server">qk3HTML5中文学习网 - HTML5先行者学习网

<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"/> qk3HTML5中文学习网 - HTML5先行者学习网


qk3HTML5中文学习网 - HTML5先行者学习网
qk3HTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助