如何计算Tex框值 [英] How to calculate Tex box Values

查看:98
本文介绍了如何计算Tex框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想在第三个文本框中计算两个文本框值,如下所示...

MRP:10000(用户将输入此值)
少:10%(用户可以在其中选择%的情况下,会从菜单中将该值下拉)
20%
30%
40%
45%
50%

价格:9000(在此文本框中,价格在选定的%上方自动计算)
8000
7000
6000
5500
5000

例如:如果我要在价格文本框8000中选择20%以上的价格,则应显示.
如果我已选择了30%以上的价格,则应显示文本框7000.

请蚂蚁给我一个想法,该如何编码????

解决方案

尝试一下:-

在表单中创建变量.我写了两遍,因为价格可能就是例如. 27.50

  double  a,b,c; 


然后我放下了1个组合框和2个文本框控件.
然后编写以下代码:-
1.首先在组合框中选择索引事件:-

 私有 无效 comboBox1_SelectedIndexChanged(对象发​​件人,EventArgs e)
{
    如果(comboBox1.SelectedValue!= " )
    {
        如果(textBox1.Text!= " )
        {
            一个= Convert.ToDouble(textBox1.Text);
            b = Convert.ToDouble(comboBox1.SelectedItem.ToString());
            c =(a * b)/ 100 ;
            textBox3.Text =(a-c).ToString();
        }
    }
} 




2.然后在文本框1的文本框changedvalue事件中:-

 私有 无效 textBox1_TextChanged(对象发​​件人,EventArgs e)
{
    如果(textBox1.Text!= " )
    {
        一个= Convert.ToDouble(textBox1.Text);
        b = Convert.ToDouble(comboBox1.SelectedItem.ToString());
        c =(a * b)/ 100 ;
        textBox3.Text =(a-c).ToString();
    }
} 



我在Combobox选定的索引更改事件中编写了相同的代码,因为如果用户更改了折扣%,则应该重新计算价格.

任何查询plz的回复或评论.
如果您找到正确的答案,则接受作为解决方案.


On下拉所选索引已更改事件

 textBox1.Text =( int  .Parse(textBox1.Text)-((< int .Parse(textBox1.Text)* Convert.ToInt32(comboBox1.SelectedValue))/ 100 )).ToString(); 


在下拉列表更改事件中,

 TextBox2.Text =( int  .Parse(textBox1.Text.ToString())-( int  .Parse(textBox1.Text.ToString())*((< int  .Parse(comboBox1.SelectedValue.ToString()))/100) ).ToString(); 


Hello All,

I want to calculate two text box values in 3rd text box like below...

MRP : 10000 (USER WILL ENTER THIS VALUE)
LESS: 10% (THIS WILL BE DROP DOWN MENU WHERE USER CAN SELECT THE %)
20%
30%
40%
45%
50%

PRICE: 9000 (IN THIS TEXT BOX PRICE AUTOMATIC CALCULATE ON ABOVE SELECTED % )
8000
7000
6000
5500
5000

for eg: IF I HAVE SELECTED 20% THAN IN PRICE TEXT BOX 8000 SHOULD BE DISPLAYED.
IF I HAVE SELECTED 30% THAN IN PRICE TEXT BOX 7000 SHOULD BE DISPLAYED.

Please ant one give me idea how to code this?????

解决方案

Try This:-

Create variable in your form. I wrote double because price may in point for eg. 27.50

double a, b,c;


then I dropped 1 combobox, and 2 textbox controls.
then write following code:-
1. First in Combo box selected Index event:-

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedValue != "")
    {
        if (textBox1.Text != "")
        {
            a = Convert.ToDouble(textBox1.Text);
            b = Convert.ToDouble(comboBox1.SelectedItem.ToString());
            c = (a * b) / 100;
            textBox3.Text = (a - c).ToString();
        }
    }
}




2. Then in textbox changedvalue event of textbox 1:-

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (textBox1.Text != "")
    {
        a = Convert.ToDouble(textBox1.Text);
        b = Convert.ToDouble(comboBox1.SelectedItem.ToString());
        c = (a * b) / 100;
        textBox3.Text = (a - c).ToString();
    }
}



I wrote the same code in Combobox selected index changed event because if the user changes the discount % then the price should be calculated again.

Any query plz reply or comment.
If You Found the answer correct then accept as solution.


On Drop down selected index changed event

textBox1.Text = (int.Parse(textBox1.Text)-((int.Parse(textBox1.Text) * Convert.ToInt32(comboBox1.SelectedValue)) / 100)).ToString();


On the dropdown changed event,

TextBox2.Text=(int.Parse(textBox1.Text.ToString())-(int.Parse(textBox1.Text.ToString())*((int.Parse(comboBox1.SelectedValue.ToString()))/100)).ToString();


这篇关于如何计算Tex框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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