Archive Browser
Download ErrorProviderTest.zip, last updated 01/01/2013 (13.74 KB)
Download- md5: ee0a54e24b2d179753dd306c58951c1a
using System;
using System.IO;
using System.Windows.Forms;
// Custom Error Provider Sample
// Copyright © 2013 Cyotek. All Rights Reserved.
// http://cyotek.com/blog/creating-a-custom-errorprovider-component-for-use-with-windows-forms-applications
// If you find this component useful, attribution or donations are welcome.
namespace ErrorProviderTest
{
public partial class TestForm : Form
{
#region Constructors
public TestForm()
{
InitializeComponent();
}
#endregion
#region Event Handlers
private void closeButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void fileNameComboBox_TextChanged(object sender, EventArgs e)
{
string errorText;
errorText = !string.IsNullOrEmpty(fileNameComboBox.Text) && !File.Exists(fileNameComboBox.Text) ? "File not found" : null;
errorProvider.SetError(fileNameComboBox, errorText);
}
private void integerTextBox_TextChanged(object sender, EventArgs e)
{
Control control;
string errorText;
int value;
control = (Control)sender;
errorText = !int.TryParse(control.Text, out value) ? "Please enter a valid integer" : null;
errorProvider.SetError(control, errorText);
}
private void submitButton_Click(object sender, EventArgs e)
{
if (errorProvider.HasErrors)
MessageBox.Show("Please resolve the validation errors before trying again.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
#endregion
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate