private void updateValues(ECurrencies source) { switch (source) //Switch on source, which we change for the call. { case ECurrencies.JPY: { amountUsd = amountJpy / 104.92; break; } case ECurrencies.GBP: { amountUsd = amountGbp / 0.72158; break; } case ECurrencies.FRF: { amountUsd = amountFrf / 5.41129; break; } case ECurrencies.DEM: { amountUsd = amountDem / 1.61345; break; } default: break; } convertFromUsd();//Sets the values for all other currencies. // Detatch the event handler functions that trigger by text changing. // This prevents a stack overflow resulting from triggering the event by changing the text in this function. textBoxUsd.TextChanged -= textBoxUsd_TextChanged; textBoxJpy.TextChanged -= textBoxJpy_TextChanged; textBoxGbp.TextChanged -= textBoxGbp_TextChanged; textBoxFrf.TextChanged -= textBoxFrf_TextChanged; textBoxDem.TextChanged -= textBoxDem_TextChanged; //textBoxUsd.Text = String.Format("{0:N0}", amountUsd); //I tried this, but then I would have to parse input which had a variety of characters thrown into it. textBoxUsd.Text = amountUsd.ToString(); textBoxDem.Text = amountDem.ToString(); textBoxFrf.Text = amountFrf.ToString(); textBoxGbp.Text = amountGbp.ToString(); textBoxJpy.Text = amountJpy.ToString(); //Reattach the event handlers that trigger by text changing. //This conundrum results because OnChange works better than OnKeyPress. //OnKeyPress will only update AFTER a press which meant that conversions were happening a step behind a change in the text. textBoxUsd.TextChanged += textBoxUsd_TextChanged; textBoxJpy.TextChanged += textBoxJpy_TextChanged; textBoxGbp.TextChanged += textBoxGbp_TextChanged; textBoxFrf.TextChanged += textBoxFrf_TextChanged; textBoxDem.TextChanged += textBoxDem_TextChanged; }
/// <summary> /// Constructor /// </summary> /// <param name="pAmount"></param> /// <param name="pCurrency"></param> public CAmount(decimal pAmount, ECurrencies pCurrency) { Amount = pAmount; Currency = pCurrency; }