如何通过将文本框中两个组合框的值相乘来显示我得到的值 [英] How do I display the value I get by multiplying the values from the two comboboxes on the textbox

查看:69
本文介绍了如何通过将文本框中两个组合框的值相乘来显示我得到的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,OTRate值未传递到文本框1

In the below code OTRate value does not get passed to the textbox1

<pre><pre><pre>

private void

private void

textBox1_TextChanged(object sender, EventArgs e)
    {
        double OTRate = (double)(comboBox3.SelectedItem) * (int)(comboBox6.SelectedItem);



        textBox1.Text = OTRate.ToString();

    }





我的尝试:



textBox1_TextChanged(object sender,EventArgs e)

{

double OTRate =(double)(comboBox3.SelectedItem)*(int) (comboBox6.SelectedItem);







textBox1.Text = OTRate.ToString();



}



What I have tried:

textBox1_TextChanged(object sender, EventArgs e)
{
double OTRate = (double)(comboBox3.SelectedItem) * (int)(comboBox6.SelectedItem);



textBox1.Text = OTRate.ToString();

}

推荐答案

Quote:

没有传递给textbox1

does not get passed to the textbox1



嗯...这可能也是,真的。

看看你的代码 - 我扯掉那些无关紧要的东西 - 很明显你有问题:


Well... that's probably just as well, really.
Look at your code - and I'll rip out the irrelevant stuff - and it's pretty obvious you have a problem:

textBox1_TextChanged(object sender, EventArgs e)
    {
    ...
    textBox1.Text = OTRate.ToString();
    }

所以......当Textbox1改变时,你为Textbox1设置一个新值。这导致更改事件发生,这意味着您处理事件,...再次更改Textbox1。这一直重复,直到每个人都厌倦,或者你杀了应用程序。



我认为你不想处理TextChanged事件来做这件事 - 如果你这样做了,您当然不想更改其中的文本!

So...when Textbox1 changes, you set a new value for Textbox1. Which causes a changed event to occur, and that means you handle the event, which...changes Textbox1 again. And this repeats until everyone gets bored, or you kill the application.

I don't think you want to handle the TextChanged event to do this - and if you do, you certainly don't want to change the text within it!


您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。 />
当代码不做ex的时候你已经接近了一个错误。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.


这篇关于如何通过将文本框中两个组合框的值相乘来显示我得到的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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