本文整理汇总了C#中System.Windows.Forms.ErrorProvider.GetError方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorProvider.GetError方法的具体用法?C# ErrorProvider.GetError怎么用?C# ErrorProvider.GetError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ErrorProvider
的用法示例。
在下文中一共展示了ErrorProvider.GetError方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetErrorMessages
public static void GetErrorMessages(Control parentControl, ICollection<string> errorList, ErrorProvider errorProvider )
{
string error = errorProvider.GetError(parentControl);
if (!string.IsNullOrWhiteSpace(error) && !errorList.Contains(error))
errorList.Add(error);
foreach (Control control in parentControl.Controls)
GetErrorMessages(control, errorList, errorProvider);
}
示例2: GetandSetErrorTest
public void GetandSetErrorTest ()
{
Form myForm = new Form ();
myForm.ShowInTaskbar = false;
Label label1 = new Label ();
Label label2 = new Label ();
ErrorProvider myErrorProvider = new ErrorProvider ();
Assert.AreEqual (string.Empty, myErrorProvider.GetError (label1), "#1");
myErrorProvider.SetError (label1, "ErrorMsg1");
Assert.AreEqual ("ErrorMsg1", myErrorProvider.GetError (label1), "#2");
Assert.AreEqual (string.Empty, myErrorProvider.GetError (label2), "#3");
myErrorProvider.SetError (label2, "ErrorMsg2");
Assert.AreEqual ("ErrorMsg2", myErrorProvider.GetError (label2), "#4");
myErrorProvider.SetError (label2, null);
Assert.AreEqual ("ErrorMsg1", myErrorProvider.GetError (label1), "#5");
Assert.AreEqual (string.Empty, myErrorProvider.GetError (label2), "#6");
myForm.Dispose ();
}
示例3: TryFocusInvalidInput
public static bool TryFocusInvalidInput(ErrorProvider errorProvider, Control control)
{
if (!string.IsNullOrEmpty(errorProvider.GetError(control)))
{
control.Focus();
return true;
}
return false;
}
示例4: SetError
public void SetError(ErrorProvider provider , Control control, string message)
{
if (!string.IsNullOrEmpty(message))
{
if (provider.GetError(control) != "")
{
provider.Clear();
Counter--;
}
else
{
provider.SetError(control,message);
Counter ++;
}
}
}
示例5: ValidationIsClearedForControlWhenControlPropertyIsSetAndErrorIsCleared
public void ValidationIsClearedForControlWhenControlPropertyIsSetAndErrorIsCleared()
{
ValidationProvider validationProvider = new ValidationProvider();
validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
MockControl control1 = new MockControl();
validationProvider.SetSourcePropertyName(control1, "StringProperty");
ValidatedControlItem controlItem1 = validationProvider.GetExistingValidatedControlItem(control1);
MockControl control2 = new MockControl();
validationProvider.SetSourcePropertyName(control2, "StringProperty");
ValidatedControlItem controlItem2 = validationProvider.GetExistingValidatedControlItem(control2);
ErrorProvider errorProvider = new ErrorProvider();
validationProvider.ErrorProvider = errorProvider;
control1.Text = "000000000001";
control2.Text = "000000000001";
validationProvider.PerformValidation(control1);
validationProvider.PerformValidation(control2);
Assert.IsFalse(validationProvider.IsValid);
Assert.IsFalse(controlItem1.IsValid);
Assert.IsFalse(controlItem2.IsValid);
Assert.AreEqual("string property", errorProvider.GetError(control1));
Assert.AreEqual("string property", errorProvider.GetError(control2));
validationProvider.ValidationPerformed += OnValidationPerformed;
validationProvider.SetSourcePropertyName(control2, "IntProperty");
Assert.IsFalse(validationProvider.IsValid);
Assert.IsFalse(controlItem1.IsValid);
Assert.IsTrue(controlItem2.IsValid);
Assert.AreEqual("string property", errorProvider.GetError(control1));
Assert.AreEqual(string.Empty, errorProvider.GetError(control2));
Assert.IsNull(validationPerformedEventArgs);
validationProvider.PerformValidation(control2);
Assert.IsFalse(validationProvider.IsValid);
Assert.IsFalse(controlItem1.IsValid);
Assert.IsFalse(controlItem2.IsValid);
Assert.AreEqual("string property", errorProvider.GetError(control1));
Assert.AreEqual("int property", errorProvider.GetError(control2));
Assert.IsNotNull(validationPerformedEventArgs);
}
示例6: ValueConvertingCallbackSettingConversionErrorMessageWillUseMessageOnErrorProviderIfExists
public void ValueConvertingCallbackSettingConversionErrorMessageWillUseMessageOnErrorProviderIfExists()
{
ValidationProvider validationProvider = new ValidationProvider();
validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
validationProvider.ValueConvert += OnValueConvertFailing;
MockControl control1 = new MockControl();
validationProvider.SetSourcePropertyName(control1, "IntProperty");
ErrorProvider errorProvider = new ErrorProvider();
validationProvider.ErrorProvider = errorProvider;
control1.Text = "5";
validationProvider.PerformValidation(control1);
Assert.IsNotNull(valueConvertEventArgs); // callback was called
Assert.AreEqual(0,
MockValidator<object>.CreatedValidators[0].ValidatedTargets.Count); // nothing got validated
Assert.IsFalse(validationProvider.IsValid); // but the provider is invalid
Assert.AreEqual("failed conversion", errorProvider.GetError(control1)); // and the error was set on the error provider
}
示例7: ValidationProvider
public void ExistingValidationErrorsAreClearedWhenDisablingValidationProviderButNotSetAgainWhenEnablingTheValidationProvider()
{
ValidationProvider validationProvider = new ValidationProvider();
validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
validationProvider.RulesetName = "validation";
MockControl control1 = new MockControl();
validationProvider.SetSourcePropertyName(control1, "StringProperty");
ErrorProvider errorProvider = new ErrorProvider();
validationProvider.ErrorProvider = errorProvider;
control1.Text = "too long";
validationProvider.PerformValidation(control1);
Assert.AreEqual("validation", errorProvider.GetError(control1));
validationProvider.Enabled = false; // set validation provider to disabled
Assert.AreEqual("", errorProvider.GetError(control1));
validationProvider.Enabled = true; // set validation provider to enabled
Assert.AreEqual("", errorProvider.GetError(control1));
}
示例8: ErrorsInErrorProviderForValidatedControlsAreClearedByValidatorProviderDispose
public void ErrorsInErrorProviderForValidatedControlsAreClearedByValidatorProviderDispose()
{
ValidationProvider validationProvider = new ValidationProvider();
validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
validationProvider.RulesetName = "validation";
ErrorProvider errorProvider = new ErrorProvider();
validationProvider.ErrorProvider = errorProvider;
MockControl controlWithoutError = new MockControl();
controlWithoutError.Text = "short";
validationProvider.SetSourcePropertyName(controlWithoutError, "StringProperty");
MockControl controlWithError = new MockControl();
controlWithError.Text = "too long";
validationProvider.SetSourcePropertyName(controlWithError, "StringProperty");
MockControl controlWithoutValidation = new MockControl();
controlWithoutValidation.Text = "too long";
validationProvider.PerformValidation(controlWithoutError);
validationProvider.PerformValidation(controlWithError);
errorProvider.SetError(controlWithoutValidation, "an unmanaged error");
Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithoutError));
Assert.AreEqual("validation", errorProvider.GetError(controlWithError));
Assert.AreEqual("an unmanaged error", errorProvider.GetError(controlWithoutValidation));
validationProvider.Dispose();
Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithoutError));
Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithError));
Assert.AreEqual("an unmanaged error", errorProvider.GetError(controlWithoutValidation));
}
示例9: ErrorProviderErrorForControlIsClearedAfterPerformingSuccessfulValidation
public void ErrorProviderErrorForControlIsClearedAfterPerformingSuccessfulValidation()
{
ErrorProvider errorProvider = new ErrorProvider();
ValidationProvider validationProvider = new ValidationProvider();
validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
validationProvider.RulesetName = "validation";
validationProvider.ErrorProvider = errorProvider;
MockControl control = new MockControl();
ValidatedControlItem validatedControlItem
= new ValidatedControlItem(validationProvider, control);
validatedControlItem.SourcePropertyName = "StringProperty";
control.Text = "too long";
validationProvider.PerformValidation(validatedControlItem);
Assert.AreNotEqual(string.Empty, errorProvider.GetError(control));
}
示例10: ValidateForm
/// <summary>
/// Validate controls in form using supplied error provider.
/// </summary>
/// <param name="erPr"></param>
/// <param name="ctrl"></param>
/// <returns></returns>
public static bool ValidateForm(ErrorProvider erPr, Control ctrl)
{
bool isValid = true;
foreach (Control control in ctrl.Controls)
{
control.Focus();
ctrl.Focus();
string msg = erPr.GetError(control);
if (msg != "")
isValid = false;
}
return isValid;
}
示例11: ShowError
/// <summary>
/// Shows error message for the given control
/// </summary>
/// <param name="control">Control</param>
/// <param name="errorProvider">Error provider</param>
/// <param name="error">Error message</param>
public static void ShowError(Control control, ErrorProvider errorProvider, string error)
{
// Current error
error = (error ?? string.Empty).Trim();
error = (error.Length == 0) ? null : error;
// Previous error
string existingError = errorProvider.GetError(control);
existingError = (existingError ?? string.Empty).Trim();
existingError = (existingError.Length == 0) ? null : existingError;
// Apply
if (error != null)
{
if (existingError == null)
{
control.Width -= 32;
}
errorProvider.SetError(control, error);
}
else
{
errorProvider.SetError(control, null);
if (existingError != null)
{
control.Width += 32;
}
}
}
示例12: txtPageBottom_ValidatedBL
public void txtPageBottom_ValidatedBL(object sender, EventArgs e)
{
try
{
bool result = Common.AssignValuePageUnit(cTool.TxtPageBottom, null);
_errProvider = Common._errProvider;
if (_errProvider.GetError(cTool.TxtPageBottom) != "")
{
_errProvider.SetError(cTool.TxtPageBottom, _errProvider.GetError(cTool.TxtPageBottom));
}
else
{
ValidatePageHeightMargins(sender, e);
}
}
catch { }
}