if you want to format the value(32.00)
but u r entering the value 23,then u just
follow the below code
call code in KeyLeave
VB.NET
Shared Sub FormatDecimal(ByVal ctxt As System.Windows.Forms.TextBox, ByVal ad As Int16)
If ctxt.Text.Trim <> "" Then
If ctxt.Text.Trim = "-" Then
MessageBox.Show("Enter Valid Inputs ", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
ctxt.SelectAll()
ctxt.Focus()
Else
If ctxt.Text.Trim = "-." Or ctxt.Text.Trim = "." Then
ctxt.Text = "0"
End If
ctxt.Text = FormatNumber(ctxt.Text.Trim, ad).Replace(",", "")
End If
End If
End Sub
C#.NET
public static void FormatDecimal(System.Windows.Forms.TextBox ctxt, Int16 ad)
{
if (ctxt.Text.Trim() != "")
{
if (ctxt.Text.Trim() == "-")
{
MessageBox.Show("Enter Valid Inputs ", "Notification", MessageBoxButtons.OK,
MessageBoxIcon.Information);
ctxt.SelectAll();
ctxt.Focus();
}
else
{
if (ctxt.Text.Trim() == "-." || ctxt.Text.Trim() == ".")
{
ctxt.Text = "0";
}
ctxt.Text = Microsoft.VisualBasic.Strings.FormatNumber(ctxt.Text.Trim(), ad,
Microsoft.VisualBasic.TriState.UseDefault, Microsoft.VisualBasic.TriState.UseDefault,
Microsoft.VisualBasic.TriState.UseDefault).Replace(",", "");
}
}
}
Happy Coding
Santosh
but u r entering the value 23,then u just
follow the below code
call code in KeyLeave
VB.NET
Shared Sub FormatDecimal(ByVal ctxt As System.Windows.Forms.TextBox, ByVal ad As Int16)
If ctxt.Text.Trim <> "" Then
If ctxt.Text.Trim = "-" Then
MessageBox.Show("Enter Valid Inputs ", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
ctxt.SelectAll()
ctxt.Focus()
Else
If ctxt.Text.Trim = "-." Or ctxt.Text.Trim = "." Then
ctxt.Text = "0"
End If
ctxt.Text = FormatNumber(ctxt.Text.Trim, ad).Replace(",", "")
End If
End If
End Sub
C#.NET
public static void FormatDecimal(System.Windows.Forms.TextBox ctxt, Int16 ad)
{
if (ctxt.Text.Trim() != "")
{
if (ctxt.Text.Trim() == "-")
{
MessageBox.Show("Enter Valid Inputs ", "Notification", MessageBoxButtons.OK,
MessageBoxIcon.Information);
ctxt.SelectAll();
ctxt.Focus();
}
else
{
if (ctxt.Text.Trim() == "-." || ctxt.Text.Trim() == ".")
{
ctxt.Text = "0";
}
ctxt.Text = Microsoft.VisualBasic.Strings.FormatNumber(ctxt.Text.Trim(), ad,
Microsoft.VisualBasic.TriState.UseDefault, Microsoft.VisualBasic.TriState.UseDefault,
Microsoft.VisualBasic.TriState.UseDefault).Replace(",", "");
}
}
}
Happy Coding
Santosh
No comments:
Post a Comment