errorprovider

c# winform控件数据验证

丶灬走出姿态 提交于 2020-04-09 11:06:01
前言 大家都知道,无论是网站还是pc端,只要涉及到输入数据的情况,我们都得考虑数据的有效性。一般两种做法,第一,当数据出现错误时捕捉异常,提示数据有问题。另一种是在提交之前就检查数据是否存在问题。很显然后一种是正道。 控件errorProvider的使用 这个控件式工具箱自带的。目的是与输入控件挂钩。其实使用方法也很简单 直接将该控件拖到窗体的某个容器下,那么该容器下的所有可输入控件都会知道感知到它的存在。 而对于可输入控件都有一个validating和validated,验证前和验证后事件。那么我们可以在该事件下自定义我们对该输入框的数据应该具有的规则。若无效,则通过erorporvider控件提示错误即可。 代码演示 private void accountNumberTextBox_Validating(object sender, CancelEventArgs e) { var txt = sender as TextBox; if (txt == null ) return; e.Cancel = (txt.Text == string.Empty); if (string.IsNullOrEmpty(txt.Text)) { errorProvider1.SetError(txt, "不可以任性,不填呀!"); } else { errorProvider1

Error Provider in WPF

孤人 提交于 2020-01-14 10:33:31
问题 I am looking at WPF componenents in the toolbox but I cannot find the error provider that is present in 2005/2008. Is it removed? 回答1: the ErrorProvider is a Winforms control. There is no equivalent in WPF. But you will still be able to find in in visual studio 2008 if you create a win forms project. You might want to take a look at this article on error validation in WPF. It has some useful suggestions and ideas for how to handle validation. 回答2: .NET 3.5 added WPF support for IDataErrorInfo

C# Displaying error messages by completing a simple registration form

谁说胖子不能爱 提交于 2019-12-13 18:20:09
问题 I'm new about C#, I learnt C programmation for one year now. I created a Window Form which asks the user to complete a registration form. My registration form I'd like to display an error message below the buttons when a field is not filled or a field isn't well used. I used this basic code : private void button1_Click(object sender, EventArgs e) { if (!isOkay(userTextBox.Text)) { label5.Text = "Please, enter an username."; label5.Visible = true; } else if (!isOkay(mailTextBox.Text)) { label5

combo box not validating

偶尔善良 提交于 2019-12-12 01:19:51
问题 I'm using ErrorProvider in windows forms for the first time. I have a simple window with a single combo box on it with several items in it, including a blank selection by default. I also have a Next button at the bottom. When I run the form and just click next with the combo box set to blank my validation doesn't trigger. Any ideas? I've wired up the error provider as provided in documentation. // Favorite Color ComboBox favoriteColorComboBox = new ComboBox(); favoriteColorComboBox.Items

Disable Whole Form by Error Provider

不想你离开。 提交于 2019-12-11 23:32:26
问题 In a Windows form I've some controls and a UserControl. I've a ErrorProvider in the UserControl. I want to stop editing all the controls in the Form if there is an error in the userControl. Is there any way to do that? I am using errorProvider.BindToCustomDataAndErrors(..) 回答1: Expose a property on the user control to indicate whether it has any errors (such as by iterating the control collection and checking errorProvider.GetError(control) Check your property and disable whatever you need to

C# error provider not working on textboxes in groupbox and tabcontrols

夙愿已清 提交于 2019-12-11 16:59:09
问题 I am trying to implement using error provider to validate that my text boxes are not empty before proceeding with execution. Error provider works on textboxes on the main form but refuses to work on any textbox or combo box that is in a groupbox or tabcontrol. It doesn't check the text boxes, it doesn't display error or waits until the user enter text/select item for the controls that are being checked. Sure if I loose the groupbox or tabcontrol I would get the error check working as normal

ErrorProvider - Change BackColor Instead of Showing Icon

和自甴很熟 提交于 2019-12-11 12:47:00
问题 I'm stuck with some legacy code that I want to upgrade a bit. I want to change the way the ErrorProvider shows the error status on a Control. Default behavior is the Icon, and a ToolTip if you hover on the icon. I would like to change this behavior to be more similar to what we use in our WPF controls. Which is a red back-color(Salmon pink) and the tool-tip on the control itself. Any tips, links or some way forward EDIT. See my answer below, on what i ended up with. 回答1: ErrorProvider

How to show an ErrorProvider error icon next to a TabPage header?

≡放荡痞女 提交于 2019-12-11 05:51:43
问题 Edit: This is not a duplicate of Icons in TabControl C# - How?. The question there is about adding icons to tab pages. Here it is about how the change the error provider error icon position to be inside the header instead of to the right of the tab page itself. Also, the error provider error icon has the functionality that when you hover the mouse on it, you see the error text, which you do not see if you simply add an icon to the header. I have a form with a TabControl . The form has also an

C# validating multiple textboxes?

▼魔方 西西 提交于 2019-12-05 04:23:38
问题 I have almost 20 textboxes and to check all i have to call validate event 20 times each using errorprovider. Is there any efficient way other than that. 回答1: this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating); this.textBox2.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating); this.textBox3.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating); // And so on for the 20 boxes. private

C# validating multiple textboxes?

↘锁芯ラ 提交于 2019-12-03 20:38:09
I have almost 20 textboxes and to check all i have to call validate event 20 times each using errorprovider. Is there any efficient way other than that. Umar Iqbal this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating); this.textBox2.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating); this.textBox3.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating); // And so on for the 20 boxes. private void textBox_Validating(object sender, CancelEventArgs e) { TextBox textbox = (TextBox)sender; // Do