本文整理汇总了VB.NET中System.Windows.Forms.ErrorProvider.GetError方法的典型用法代码示例。如果您正苦于以下问题:VB.NET ErrorProvider.GetError方法的具体用法?VB.NET ErrorProvider.GetError怎么用?VB.NET ErrorProvider.GetError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ErrorProvider 的用法示例。
在下文中一共展示了ErrorProvider.GetError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1:
Private Sub TextBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
' If nothing is entered,
' an ArgumentException is caught; if an invalid directory is entered,
' a DirectoryNotFoundException is caught. An appropriate error message
' is displayed in either case.
Try
Dim directory As New System.IO.DirectoryInfo(TextBox1.Text)
directory.GetFiles()
ErrorProvider1.SetError(TextBox1, "")
Catch ex1 As System.ArgumentException
ErrorProvider1.SetError(TextBox1, "Please enter a directory")
Catch ex2 As System.IO.DirectoryNotFoundException
ErrorProvider1.SetError(TextBox1, _
"The directory does not exist." & _
"Try again with a different directory.")
End Try
End Sub
' This method handles the LostFocus event for TextBox1 by setting the
' dialog's InitialDirectory property to the text in TextBox1.
Private Sub TextBox1_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.LostFocus
OpenFileDialog1.InitialDirectory = TextBox1.Text
End Sub
' This method demonstrates using the ErrorProvider.GetError method
' to check for an error before opening the dialog box.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'If there is no error, then open the dialog box.
If ErrorProvider1.GetError(TextBox1) = "" Then
Dim dialogResult As DialogResult = OpenFileDialog1.ShowDialog()
End If
End Sub
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:43,代码来源:ErrorProvider.GetError
示例2: DeferredValidation
' 导入命名空间
Imports System.Windows.Forms
public class DeferredValidation
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating, TextBox2.Validating, TextBox3.Validating
If (TextBox1.Text.Length <> 0) And Not (TextBox1.Text Like "##") _
Then
ErrorProvider1.SetError(TextBox1, TextBox1.Name & " must contain exactly two digits")
Else
ErrorProvider1.SetError(TextBox1, "")
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
If IsInvalidField(TextBox1) Then Exit Sub
If IsInvalidField(TextBox3) Then Exit Sub
e.Cancel = False
End Sub
Private Function IsInvalidField(ByVal ctl As Control) As Boolean
If ErrorProvider1.GetError(ctl).Length = 0 Then
Return False
Else
MessageBox.Show(ErrorProvider1.GetError(ctl))
ctl.Focus()
Return True
End If
End Function
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Public Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider(Me.components)
CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Five Digits"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(72, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(80, 20)
Me.TextBox1.TabIndex = 1
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(72, 32)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(80, 20)
Me.TextBox2.TabIndex = 3
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(8, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 13)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Five Digits"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(72, 56)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(80, 20)
Me.TextBox3.TabIndex = 5
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(8, 56)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 13)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Five Digits"
'
'ErrorProvider1
'
Me.ErrorProvider1.ContainerControl = Me
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(210, 83)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Deferred Validation"
CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
End Class
开发者ID:VB程序员,项目名称:System.Windows.Forms,代码行数:150,代码来源:ErrorProvider.GetError
注:本文中的System.Windows.Forms.ErrorProvider.GetError方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论