Posts Tagged ‘ C# ’

Number Only TextBox C# Windows Application

Put this code snippet your TextBox KeyPress Event, you will have your Number Only TextBox Working.


private void numberOnlyTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
 //allow digits only
 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
 {
   e.Handled = true;
 }

 // allow one decimal point
 if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
 {
  e.Handled = true;
 }
}


Thanks
A Rahim Khan

How to delete files from a specific folder using datetime constraint (C# code)

To delete files from a specific folder you can use following code snippet written in c#.


foreach (FileInfo fileInformation in new DirectoryInfo(@”I:/TrialTesting/”).GetFiles())
{
  File.Delete(fileInformation.FullName);                        
}

Continue reading

C# date validation

There is no direct built-in function or method to validate DateTime Data Type in C#. This following self-explanatory code snippet shows a method that takes string as argument and validates it using ParseExact Method of DateTime. Moreover, you can choose any Date Format / Style for validation. Continue reading

Form Closing Event in C# (Windows Application)

Sometimes, Developers don’t want Users to close or leave a Form right away as Application still has some back ground process going on or it requires a confirmation before closing. In C# Windows Application, you can code at FormClosing Event. Have a look at this code snippet. Continue reading

Modal From in C#

Almost all Desktop Application Developers are familiar with Modal Form. It restricts user from opening any other Forms without closing the opened one. Do you know how to get this done in C# ? If your answer is “NO”, you are at the right place. It’s very simple. Continue reading