I'd approach this in three steps:
1. if I had thoroughly examined every possible use of a MaskedTextBox, with setting the 'Culture property to "eu-ES", so that, theoretically, I could get results in € vs. US $ ... and was not satisfied with the result ...
... then ...
2. if I had searched CP, and the net, for somebody already having worked out an elegant solution for this, and I did not find something already adequate:
... then ...
3. I'd create a UserControl that contained two NumericUpDown Controls, both with the 'DecimalPlaces property set to #0. The left one would hold the integer Pound amount, the right the integer that will become the fractional part of the return value.
a. I'd create a Public Property of Type Decimal to make the result available to outside consumers of the UserControl.
b. I'd set the right NumericUpDown to have a Minimum value of #0, and a Maximum value of #99.
c. I'd set the Maximum value of the left NumericUpDown to the largest possible amount I wanted to allow to be entered, and its Minimum to #0,
d. In that UserControl I'd "wire up" the same KeyPress EventHandler to both NumericUpDown Controls: in that KeyPress EventHandler (as shown below): I'd intercept the Enter key
e. On the Enter key being pressed: I'd update the Public property described in "3a." above. Dividing the right NumericUpDown control value by #100 to get the "decimal part" (as shown below).
The code might look like this:
namespace TestCurrencyEntry
{
public partial class MyPoundEntry : UserControl
{
public MyPoundEntry()
{
InitializeComponent();
}
public decimal ResultInPounds { get; set; }
private void PoundEntry_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
ResultInPounds = numericUpDown1.Value + (numericUpDown2.Value/100);
}
}
}
}
Discussion:
1. I'd consider on Entry into the UserControl setting the Focus to the Left NumericUpDown Control.
2. Given the two NumericUpDown Controls are in the proper tab-order, then you can easily start entering the integer amount in the left NUD control, then, hit the tab-key, and continue entering the integers in the right NUD that will become the decimal amount.
3. Depending on application requirements, I might want to raise an Event whenever the value was changed.