![]() ![]() For example, if the error occurs in the TxtSource control, the TabControl1.SelectedTab command is set to TabControl1.SelectedTab=TabSource. The command TabControl1.SelectedTab is used to set the focus of the control on the tab page on which the error occurs. The command sets the focus of the application on the TxtSource, TxtDestination, or TxtProcessed text boxes, depending on the text box whose path is not in the specified format. The Focus() method is used to set the focus on the specified control. In the preceding code, the SetError method is used to associate the text boxes with the error message. As previously mentioned, the SetError method accepts two parameters: the name of the control and the error string. The SetError method is used to attach the error message to a control. If the Directory.Exists command returns false, the code will generate an error message. The preceding code checks to see if the specified directory exists. ErrMessage.SetError(TxtProcessedFile, "") ErrMessage.SetError(TxtProcessedFile, "Invalid processed file directory")ģ0. If (Directory.Exists(TxtProcessedFile.Text) = False) ThenĢ5. ErrMessage.SetError(TxtDestination, "")Ģ4. ErrMessage.SetError(TxtDestination, "Invalid destination directory")ġ8. If (Directory.Exists(TxtDestination.Text) = False) Thenġ6. ErrMessage.SetError(TxtSource, "Invalid source directory")ġ5. If (Directory.Exists(TxtSource.Text) = False) Thenħ. Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.ClickĦ. Now you need to add the following code to the Click event of the OKīutton to display the specified error message if the directory structure is not correct:Ĥ. ![]() You'll specify the error message and associate it with the TxtSource, TxtDestination, and TxtProcessedFile text boxes.ģ. You now need to specify an error message and associate it with the controls that need to be validated. Change the Name property of the ErrorProvider control to ErrMessage. Drag the ErrorProvider control from the Windows Forms toolbox to the form.Ģ. Let's now add an ErrorProvider control to the form.ġ. The SetError method accepts two parameters: the name of the control with which the error message is attached and the string that will be displayed when the user points the mouse toward the error message icon. To display the error message, you use the SetError method. In addition to displaying the icon, the ErrorProvider control also displays an error message when the user points toward the error message icon. By default, Visual Studio.NET displays the icon shown in Figure 32-3.įigure 32-3: The Windows form showing the error message icon You can change the icon, however, by changing the Icon property of the ErrorProvider control. Next you need to specify the icon that will be displayed when an error occurs. To insert an ErrorProvider control into the form, drag the ErrorProvider control to the Windows form. The ErrorProvider displays an error message in a nonobstructive way if the data entered by the user is not in the specified format. The ErrorProvider control is used to validate the data entered by a user. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |