简体   繁体   English

链接两个文本框,以便在一个文本框中进行更改会导致在另一个文本框中进行更改,反之亦然。

[英]Linking two Text Boxes so that changes in one text box causes change in another and vice versa.

I want to write a simple program in C# that performs conversion from kVA rating to kW rating and calculate Current ratings of a electricity generator at fixed voltage level and PowerFactor. 我想用C#编写一个简单的程序,该程序执行从kVA额定值到kW额定值的转换,并计算固定电压水平和PowerFactor时发电机的电流额定值。

What the program would do is the user enter value in any of the three textboxes (let say kVA) and the program calculate other two parameters (kW and Current) in respective textbox without pressing any other button. 程序将执行的操作是用户在三个文本框中的任何一个中输入值(假设为kVA),并且程序无需按任何其他按钮即可在相应的文本框中计算其他两个参数(kW和Current)。

after that when the user changes the value of other two parameter (say kW) then program would recalculate kVA and Current. 之后,当用户更改其他两个参数的值(例如kW)时,程序将重新计算kVA和Current。

Same with the current textbox. 与当前文本框相同。

You need something like this: 您需要这样的东西:

On Form Load: 表单加载时:

Textbox1.KeyUp += ProcessChange;
Textbox2.KeyUp += ProcessChange;

Then the ProcessChange handler: 然后是ProcessChange处理程序:

private void ProcessChange(object sender, KeyEventArgs ka)
{
   if(sender == Textbox1)
   {
      //do work...
   }

   else //sender==Textbox2
   {
      //do work...
   }
}

This should get you going in the right direction... 这应该使您朝正确的方向前进...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM