TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shovan Saha
NA
321
91.9k
Please check my code
Aug 18 2017 5:56 PM
C# visual studio 2015, Windows Form. I have a text box and three labels. I want to write in text box only number and decimal place two. But I can not write in the text box as 0.52 or 052. If I write with . or 0 the program does not continue. I need, I can start write in textbox with 0.## if first 0 is problem then message box will show but the program will continue. Please help me at this regard.
private void txtAPenPension_TextChanged(object sender, EventArgs e)
{
if (Regex.IsMatch(txtAPenPension.Text, " ^ [0-9]"))
{
txtAPenPension.Text = "";
}
double tk1, tkS1, tkD1;
tk1 = double.Parse(txtAPenPension.Text);
tkS1 = tk1 * 0.01;
tkD1 = tk1 + tkS1;
if (txtAPenPension.Text != "")
{
lblAPenPorishodh.Text = string.Format("{0:F2}", tk1);
lblAPenServiceCharge.Text = string.Format("{0:F2}", tkS1);
lblAPenDabi.Text = string.Format("{0:F2}", tkD1);
return;
}
}
private void txtAPenPension_KeyPress(object sender, KeyPressEventArgs e)
{
string senderText = (sender as TextBox).Text;
string senderName = (sender as TextBox).Name;
string[] splitByDecimal = senderText.Split('.');
int cursorPosition = (sender as TextBox).SelectionStart;
if (!char.IsControl(e.KeyChar)
&& !char.IsDigit(e.KeyChar)
&& (e.KeyChar != '.'))
{
e.Handled = true;
}
if (e.KeyChar == '.'
&& senderText.IndexOf('.') > -1)
{
e.Handled = true;
}
if (!char.IsControl(e.KeyChar)
&& senderText.IndexOf('.') < cursorPosition
&& splitByDecimal.Length > 1
&& splitByDecimal[1].Length == 2)
{
e.Handled = true;
}
}
Reply
Answers (
1
)
Why We use Delegate BY using object we may call method
Trouble in calling functions written in web service in .net