Bob Log III al Tetris

e se fate i bravi metto anche un video…
Archivio AutoreNella sua classificazione, Vladimir Jankélévitch distingue la menzogna in base al rapporto che intrattiene con la verità. E dunque c’è la dissimulazione, quando ci si limita a nascondere la verità (Berlusconi ha detto: “Non ho mai voluto candidare veline, non frequento minorenni”). L’alterazione, quando si modifica la natura del vero (Berlusconi ha detto: “Non sapevo che Patrizia fosse una prostituta”). La deformazione, quando se ne ingrandisce o se ne rimpicciolisce il formato (Berlusconi ha detto: “Ho visto tre, quattro volte Noemi e sempre con i genitori”). L’antegoria, quando si dice l’assoluto contrario (Berlusconi ha detto: “Non ho mai pagato una prostituta”). La fabulazione, quando invece di mascherare la verità, la si inventa di sana pianta (Berlusconi ha detto: “C’è un progetto eversivo contro di me”). Leggi tutto qua Tag:berlusconiI used to get the form validation by hand, with some ugly checks, message boxes, several boolean variables to combine with a lot of operators && and ||. A TOTAL mess. My target was to provide a simple validation tool that I can spread (by inheritance) to all the forms in a project. How to get itIn a base form class, the parent of all my forms in the project, get an instance of an ErrorProvider, by putting it into the form. Be sure to have “Modifier” property set to “Protected”.
namespace ValidationTest{
public partial class MyBaseForm
{
...
protected void ValidateControlHandler(object sender, CancelEventArgs e)
{
// this string will be the tooltip shown when an error appears
String error = null;
String textToCheck = String.Empty;
// we need to be sure that the sender control is
// of the type System.TextBox
Type senderType = sender.GetType();
if (senderType == typeof(TextBox))
textToCheck = ((TextBox)sender).Text;
else
throw new ArgumentException(
"The sender is not a TextBox, but a " + senderType.Name);
// Mandatory field: if the textToCheck is null or empty, fire up the error
if (String.IsNullOrEmpty(textToCheck))
{
error = "Mandatory field";
// this CancelEventArgs property locks the pointer over the control
// until the error disappears
e.Cancel = true;
}
// if there isn't any error, the SetError get a
// null string and it will not shown.
// otherwise the SetError will show an icon and a tooltip
// next to the control that fails the validation
errorProvider.SetError((Control)sender, error);
}
protected void SetValidationHandlerOnControl(Control ctrl)
{
// we need to be sure that the sender control
// is of the type System.TextBox
Type ctrlType = ctrl.GetType();
if (ctrlType == typeof(TextBox))
ctrl.Validating += new CancelEventHandler(this.ValidateControlHandler);
}
}
}
Ok, that’s almost done.
namespace ValidationTest{
public partial class MyChildForm : MyBaseForm
{
public MyChildForm(){
InitializeComponent();
SetValidationHandlerOnControl(this.textBox1);
SetValidationHandlerOnControl(this.textBox2);
SetValidationHandlerOnControl(this.textBox3);
...
}
}
}
that’s it! EDIT: corrected a typo. Sorry! Tag:.Net, best-practices, c#, coding, how-to, Informatica, visual studioHello everybody! |




















Articoli (RSS)