熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

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

2022-06-13   來源: .NET編程 

  文件:
  Calculateaspx
  bin/Calculatecs
  bin/Calculatebat

  步驟:
  Calculatecs

  namespace Calculate
  {
   using System;
   public class math
   {
    public String _color;
    public int Add(int aint b)
    {
     return a+b;
    }
    public int Sub(int aint b)
    {
     return ab;
    }
    public int Mul(int aint b)
    {
     return a*b;
    }
    public String Color
    {
     get
     {
      return _color;
     }
     set
     {
      _color=value;
     }
    }
   }
  }

  Calculatebat

  csc /t:library /out:Calculatedll Calculatecs

  執行Calculatebat

  Calculateaspx

  <%@Import NameSpace=Calculate%>

  <script language=c# runat=server>
  public String color;
  void DoAdd(Object Src EventArgs E)
  {
   math math=new math();
   MessageText=mathAdd(ConvertToInt(AValue)ConvertToInt(BValue))ToString();
   mathColor=CValue;
   color=mathColor;
  }
  void DoSub(Object Src EventArgs E)
  {
   math math=new math();
   MessageText=mathSub(ConvertToInt(AValue)ConvertToInt(BValue))ToString();
   mathColor=CValue;
   color=mathColor;
  }
  void DoMul(Object Src EventArgs E)
  {
   math math=new math();
   MessageText=mathMul(ConvertToInt(AValue)ConvertToInt(BValue))ToString();
   mathColor=CValue;
   color=mathColor;
  }

  </script>
  <font id=Cau color=<%ResponseWrite(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/>


From:http://tw.wingwit.com/Article/program/net/201311/15299.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.