最近开始接触.NET,有些看似简单的问题,做起来挺费劲的,以前也没有开发的经验。有个小问题再次请教下朋友们:HTML页面代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
A:<asp:TextBox ID="txtA" runat="server"></asp:TextBox>
<br />
B:<asp:TextBox ID="txtB" runat="server"></asp:TextBox>
<br />
C:<asp:TextBox ID="txtC" runat="server"></asp:TextBox>
<br />
Portion:<asp:TextBox ID="txtPortion" runat="server"></asp:TextBox>
<asp:Button ID="btnPortion" runat="server" Text="点击根据A,B,C的值自动生成比例值" OnClick="btnPortion_OnClick"/>
<br />
Total:<asp:TextBox ID="txtTotal" runat="server" Width="165px"></asp:TextBox>
<asp:Button ID="btnTotal" runat="server" Text="点击根据A,B,C的值求和" OnClick="btnTotal_OnClick"/>
</div>
</form>
</body>
</html>比例值,比如说A是40,B是60,C是20,则txtPortion显示的值就是: 2:3:1
txtTotal计算的和就是:120
请问,这样的小需求,该如何写CS代码?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
A:<asp:TextBox ID="txtA" runat="server"></asp:TextBox>
<br />
B:<asp:TextBox ID="txtB" runat="server"></asp:TextBox>
<br />
C:<asp:TextBox ID="txtC" runat="server"></asp:TextBox>
<br />
Portion:<asp:TextBox ID="txtPortion" runat="server"></asp:TextBox>
<asp:Button ID="btnPortion" runat="server" Text="点击根据A,B,C的值自动生成比例值" OnClick="btnPortion_OnClick"/>
<br />
Total:<asp:TextBox ID="txtTotal" runat="server" Width="165px"></asp:TextBox>
<asp:Button ID="btnTotal" runat="server" Text="点击根据A,B,C的值求和" OnClick="btnTotal_OnClick"/>
</div>
</form>
</body>
</html>比例值,比如说A是40,B是60,C是20,则txtPortion显示的值就是: 2:3:1
txtTotal计算的和就是:120
请问,这样的小需求,该如何写CS代码?
解决方案 »
- c# 安装程序中.net framework包的问题
- 在winfrom 中怎么同时拖动多个控件
- 大家在什么情况下才需要在自定义类方法中捕获异常
- Web接收TCP发送数据
- 在C#中,如何用webbrowser控件获取网页内的一个变量的值?如何获取一个控件的值呢?比如文本框的值。
- 如何判断无名线程是由哪些代码产生的?
- VS2005站点发布
- 关于c# 中的FileSystemWatcher事件触发问题,从一个文件夹复制到另一文件夹,只让其触发一次新建OnCreate避免同时触发OnChanged
- 请教有关ADO。NET的问题.解决了马上给分,结贴
- 怎么做一个输入法窗体
- .net加密狗的问题
- 关于动态行列装换
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;namespace CocisWeb.DevelopHelp
{
public partial class TestAppPortion : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
}
} public void btnPortion_OnClick(object sender,EventArgs e)
{
TestAppPortion m = new TestAppPortion();
int n1 = Convert.ToInt32(txtA.Text);
int n2 = Convert.ToInt32(txtB.Text);
this.txtPortion.Text = m.maxGongYueShu(n1, n2).ToString();
} public float maxGongYueShu(int n1, int n2)
{
int temp = Math.Max(n1, n2);
n2 = Math.Min(n1, n2);//n2中存放两个数中最小的
n1 = temp;//n1中存放两个数中最大的
while (n2 != 0)
{
n1 = n1 > n2 ? n1 : n2;//使n1中的数大于n2中的数
int m = n1 % n2;
n1 = n2;
n2 = m;
}
return n1;
} public void Main(string[] args)
{
int n1 = Convert.ToInt32(txtA.Text);
int n2 = Convert.ToInt32(txtB.Text);
if (n1 * n2 != 0)
{
TestAppPortion m = new TestAppPortion();
Console.WriteLine(m.maxGongYueShu(n1, n2));
}
else
{
Console.WriteLine("这两个数不能为0");
}
}
}
}
http://baike.baidu.com/view/47637.htm#4
public void btnTotal_OnClick(object sender,EventArgs e)
{
int sum=0;
int S1 = Convert.ToInt32(this.txtA.Text);
int S2 = Convert.ToInt32(this.txtB.Text);
int S3 = Convert.ToInt32(this.txtC.Text);
sum= S1 + S2 + S3;
this.txtTotal.Text = sum.ToString();
}
计算A,B的比例值,也搞定了,若加上C,改怎么变换呢?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;namespace CocisWeb.DevelopHelp
{
public partial class TestAppPortion : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
}
} public void btnPortion_OnClick(object sender,EventArgs e)
{
TestAppPortion m = new TestAppPortion();
int n1 = Convert.ToInt32(txtA.Text);
int n2 = Convert.ToInt32(txtB.Text);
this.txtPortion.Text = (n1 / m.maxGongYueShu(n1, n2)).ToString() + ":" + (n2 / m.maxGongYueShu(n1, n2)).ToString();
} public float maxGongYueShu(int n1, int n2)
{
int temp = Math.Max(n1, n2);
n2 = Math.Min(n1, n2);//n2中存放两个数中最小的
n1 = temp;//n1中存放两个数中最大的
while (n2 != 0)
{
n1 = n1 > n2 ? n1 : n2;//使n1中的数大于n2中的数
int m = n1 % n2;
n1 = n2;
n2 = m;
}
return n1;
} public void Main(string[] args)
{
int n1 = Convert.ToInt32(txtA.Text);
int n2 = Convert.ToInt32(txtB.Text);
if (n1 * n2 != 0)
{
TestAppPortion m = new TestAppPortion();
Console.WriteLine(m.maxGongYueShu(n1, n2));
}
else
{
Console.WriteLine("这两个数不能为0");
}
} public void btnTotal_OnClick(object sender,EventArgs e)
{
int sum=0;
int S1 = Convert.ToInt32(this.txtA.Text);
int S2 = Convert.ToInt32(this.txtB.Text);
int S3 = Convert.ToInt32(this.txtC.Text);
sum= S1 + S2 + S3;
this.txtTotal.Text = sum.ToString();
} }
}
{
Int32 i1 = Convert.ToInt32(textBox1.Text);
Int32 i2 = Convert.ToInt32(textBox2.Text);
Int32 i3 = Convert.ToInt32(textBox3.Text); Int32 min = Math.Min(i1, i2);
min = Math.Min(min, i3); for (int i = min-1; i >0 ; i--)
{
if (
(i1 % i == 0) &&
(i2 % i == 0) &&
(i3 % i == 0)
)
{
i1 = i1 / i;
i2 = i2 / i;
i3 = i3 / i;
textBox4.Text = i1.ToString() + "/" + i2.ToString() + "/" + i3.ToString();
return;
}
}
}
for (int i = min; i >0 ; i--)感谢各位的热心参与,此需求成功实现!