Articles in this section
Category / Section

How to handle Got and LostFocus events in WinForms CurrencyTextBox?

1 min read

 

We can workaround the behaviour for now by handling the GotFocus and LostFocus events of WinForms  CurrencyTextBox. Though we cannot hide the zeros ,you can set it in such a way that whenever the control does not have focus,it hides zeros.However, when it gets focus it shows the zeros according to the decimal digits.

C#

private void currencyTextBox1_GotFocus(object sender, System.EventArgs e)
{
this.currencyTextBox1.CurrencyDecimalDigits = 6;
}
 
private void currencyTextBox1_LostFocus(object sender, System.EventArgs e)
{
string dblval = this.currencyTextBox1.DecimalValue.ToString();
int decimalpos = this.currencyTextBox1.Text.IndexOf(".");
int len = dblval.TrimEnd(''0'').Substring(decimalpos).Length;
this.currencyTextBox1.CurrencyDecimalDigits = len;
}

VB

Private Sub currencyTextBox1_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles currencyTextBox1.GotFocus
Me.currencyTextBox1.CurrencyDecimalDigits = 6
End Sub
 
Private Sub currencyTextBox1_LostFocus(ByVal sender As Object, ByVal e As EventArgs) Handles currencyTextBox1.LostFocus
Dim dblval As String = Me.currencyTextBox1.DecimalValue.ToString()
Dim decimalpos As Integer = Me.currencyTextBox1.Text.IndexOf(".")
Dim len As Integer = dblval.TrimEnd("0"c).Substring(decimalpos).Length
Me.currencyTextBox1.CurrencyDecimalDigits = len
End Sub


Conclusion

I hope you enjoyed learning how to handle Got and LostFocus events in WinForms CurrencyTextBox.

You can refer to WinForms Currency Textbox feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Currency Textbox example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied