Loading...
Loading...
Implement currency input controls in Windows Forms applications using Syncfusion CurrencyTextBox. Use this skill when developers need to create currency entry fields with validation, formatting, decimal handling, positive/negative color coding, and clipboard support. Essential for financial forms, payment inputs, budget applications, and any scenario requiring validated currency input.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-currency-textboxusing System.Windows.Forms;
using Syncfusion.Windows.Forms.Tools;
public partial class Form1 : Form
{
private CurrencyTextBox currencyTextBox1;
public Form1()
{
InitializeComponent();
// Create and configure CurrencyTextBox
currencyTextBox1 = new CurrencyTextBox();
currencyTextBox1.Location = new System.Drawing.Point(10, 10);
currencyTextBox1.Size = new System.Drawing.Size(200, 25);
// Set currency format
currencyTextBox1.CurrencySymbol = "$";
currencyTextBox1.CurrencyDecimalDigits = 2;
currencyTextBox1.CurrencyGroupSeparator = ",";
currencyTextBox1.CurrencyGroupSizes = new int[] { 3 };
// Set value constraints
currencyTextBox1.MaxValue = 999999.99m;
currencyTextBox1.MinValue = 0m;
currencyTextBox1.DecimalValue = 100.00m;
// Set colors for value states
currencyTextBox1.PositiveColor = System.Drawing.Color.Black;
currencyTextBox1.NegativeColor = System.Drawing.Color.Red;
currencyTextBox1.ZeroColor = System.Drawing.Color.Gray;
this.Controls.Add(currencyTextBox1);
}
}// For collecting currency amounts (payments, invoices, etc.)
currencyTextBox.MaxValue = decimal.MaxValue;
currencyTextBox.MinValue = 0m;
currencyTextBox.CurrencySymbol = "$";
currencyTextBox.CurrencyDecimalDigits = 2;
currencyTextBox.AllowNull = false;// Color-code by sign (green for profit, red for loss)
currencyTextBox.PositiveColor = System.Drawing.Color.Green;
currencyTextBox.NegativeColor = System.Drawing.Color.Red;
currencyTextBox.MaxValue = decimal.MaxValue;
currencyTextBox.MinValue = decimal.MinValue;// Allow null values with custom placeholder text
currencyTextBox.AllowNull = true;
currencyTextBox.NullString = "(Not Specified)";
currencyTextBox.Text = "";// Handle KeyDown event to add multiplier shortcuts
private void currencyTextBox1_KeyDown(object sender, KeyEventArgs e)
{
decimal value = currencyTextBox1.DecimalValue;
switch(e.KeyCode)
{
case Keys.G: // Giga (billion)
currencyTextBox1.DecimalValue = value * 1000000000m;
break;
case Keys.M: // Mega (million)
currencyTextBox1.DecimalValue = value * 1000000m;
break;
case Keys.K: // Kilo (thousand)
currencyTextBox1.DecimalValue = value * 1000m;
break;
}
}| Property | Type | Purpose | Common Values |
|---|---|---|---|
| DecimalValue | decimal | Get/set numeric value programmatically | Any valid decimal |
| CurrencySymbol | string | Currency symbol display | "$", "€", "£", "¥" |
| CurrencyDecimalDigits | int | Decimal places displayed | 2, 3, 4 |
| CurrencyGroupSeparator | string | Thousands separator | ",", ".", " " |
| MaxValue | decimal | Maximum allowed value | 999999.99, 100000, etc. |
| MinValue | decimal | Minimum allowed value | 0, -999999.99, etc. |
| PositiveColor | Color | Color for positive values | Color.Black, Color.Green |
| NegativeColor | Color | Color for negative values | Color.Red, Color.Maroon |
| ZeroColor | Color | Color for zero value | Color.Gray, Color.DarkGray |
| TextAlign | HorizontalAlignment | Text position | Left, Center, Right |
| BorderStyle | BorderStyle | Border appearance | FixedSingle, Fixed3D, None |
| AllowNull | bool | Allow empty/null values | true, false |
| ShowOverflowIndicator | bool | Show indicator when value exceeds bounds | true, false |