目标寻求百分比的C#代码 [英] C# code for Percentage in Goal Seek

查看:77
本文介绍了目标寻求百分比的C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要开发一个应用程序

,其中需要实现目标搜索功能以进行百分比计算。



喜欢

I need to develop an application
where Goal seek function need to be implemented for percentage calculation.

Like

A1     b1   c1   d1
2000   4    80  2080


当我更改d1单元格值时


A1单元格值应该使用目标搜索在excel中更改。



同样的概念需要在C#中实现


when I change the d1 cell value
A1 cell value should get changed in excel using goal seek.

Same concept need to be implemented in C#

textbox1  textbox2  textbox3   textBox4   
 2000      4         80          2080      



如果我改变textbox4然后TextBox1中和textbox3会得到改变



有可能吗?



如果是,那么请帮助


If I change textbox4 then textbox1 and textbox3 would get change

Is it possible?

If yes then please help

推荐答案

是 - 只处理文本框的TextChanged事件,并设置另一个事件的值。

Yes - just handle the TextChanged event for the textbox, and set the value of the other one.
textbox1.Text = (int.Parse(textbox4.Text) - int.Parse(textbox3.Text)).ToString();



显然,你需要在那里放置检查以确保这些方框是数字的,等等。


Clearly, you will want to put checking in there to make sure the boxes are numeric, and so forth.


可以轻松完成TextChanged事件和文本框中的autopostback



Can be done easily with TextChanged event and autopostback in text box

<form runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  <asp:TextBox ID="TextBox4" runat="server" ontextchanged="TextBox4_TextChanged"

      style="height: 22px" AutoPostBack=true></asp:TextBox>
  </form>







和cs编码








and the cs coding


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox3.Text = "0";


    }



    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {
     TextBox1.Text = (int.Parse(TextBox4.Text)- int.Parse(TextBox3.Text)).ToString();
    }
}


这是代码



this is the code

double a, b, c,v,d;
           bool x = double.TryParse(textBox2.Text, out a);
           b = (a / 100) + 1;
           x = double.TryParse(textBox1.Text, out v);
           c = v / b;
           d = c * a / 100;
           c = Math.Round(c, 2);
           d = Math.Round(d, 2);
           textBox3.Text = c.ToString();
           textBox4.Text = d.ToString();


这篇关于目标寻求百分比的C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆