AutoValidate 열거형

정의

컨트롤이 사용자 입력 포커스를 잃을 때 컨트롤 데이터의 유효성을 검사하는 방법을 결정합니다.Determines how a control validates its data when it loses user input focus.

public enum class AutoValidate
public enum AutoValidate
type AutoValidate = 
Public Enum AutoValidate
상속
AutoValidate

필드

Disable 0

암시적 유효성 검사가 수행되지 않습니다.Implicit validation will not occur. 이 값을 설정해도 Validate() 또는 ValidateChildren()에 대한 명시적 호출에는 방해가 되지 않습니다.Setting this value will not interfere with explicit calls to Validate() or ValidateChildren().

EnableAllowFocusChange 2

암시적 유효성 검사가 수행되지만 유효성 검사에 실패하면 포커스가 새 컨트롤로 변경됩니다.Implicit validation occurs, but if validation fails, focus will still change to the new control. 유효성 검사에 실패하면 Validated 이벤트가 발생하지 않습니다.If validation fails, the Validated event will not fire.

EnablePreventFocusChange 1

컨트롤이 포커스를 잃으면 암시적 유효성 검사가 수행됩니다.Implicit validation occurs when the control loses focus.

Inherit -1

컨트롤은 폼이나 다른 컨트롤 등의 컨테이너에서 AutoValidate 동작을 상속합니다.The control inherits its AutoValidate behavior from its container (such as a form or another control). 컨테이너 컨트롤이 없으면 EnablePreventFocusChange가 기본값이 됩니다.If there is no container control, it defaults to EnablePreventFocusChange.

예제

다음 코드 예제는 양식 및 포함된 된 컨트롤의 모든 암시적 유효성 검사가 해제 하 고 마우스 단추를 클릭할 때 대신 유효성 검사의 모든 폼의 자식을 수동으로 수행 합니다.The following code example turns off implicit validation for a form and all of its contained controls, and instead manually performs validation of all of the form's children when a mouse button is clicked.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Text;

namespace TestValidation
{
    class Form1 : Form
    {
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }

        private TextBox firstNameBox, lastNameBox;
        private Button validateButton;
        private FlowLayoutPanel flowLayout1;

        private Form1()
        {
            this.Load += new EventHandler(Form1_Load);
        }

        void Form1_Load(object sender, EventArgs e)
        {
            // Turn off validation when a control loses focus. This will be inherited by child
            // controls on the form, enabling us to validate the entire form when the 
            // button is clicked instead of one control at a time.
            this.AutoValidate = AutoValidate.Disable;

            flowLayout1 = new FlowLayoutPanel();
            flowLayout1.Dock = DockStyle.Fill;
            flowLayout1.Name = "flowLayout1";

            firstNameBox = new TextBox();
            firstNameBox.Name = "firstNameBox";
            firstNameBox.Size = new Size(75, firstNameBox.Size.Height);
            firstNameBox.CausesValidation = true;
            firstNameBox.Validating += new System.ComponentModel.CancelEventHandler(firstNameBox_Validating);
            flowLayout1.Controls.Add(firstNameBox);

            lastNameBox = new TextBox();
            lastNameBox.Name = "lastNameBox";
            lastNameBox.Size = new Size(75, lastNameBox.Size.Height);
            lastNameBox.CausesValidation = true;
            lastNameBox.Validating += new System.ComponentModel.CancelEventHandler(lastNameBox_Validating);
            flowLayout1.Controls.Add(lastNameBox);

            validateButton = new Button();
            validateButton.Text = "Validate";
            // validateButton.Location = new Point(170, 10);
            validateButton.Size = new Size(75, validateButton.Size.Height);
            validateButton.Click += new EventHandler(validateButton_Click);
            flowLayout1.Controls.Add(validateButton);

            this.Controls.Add(flowLayout1);

            this.Text = "Test Validation";
        }

        void firstNameBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (firstNameBox.Text.Length == 0)
            {
                e.Cancel = true;
            }
            else
            {
                e.Cancel = false;
            }
        }

        void lastNameBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = false;
        }

        void validateButton_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                MessageBox.Show("Validation succeeded!");
            }
            else
            {
                MessageBox.Show("Validation failed.");
            }
        }
    }
}
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Inherits Form

    'Entry point which delegates to C-style main Private Function
    Public Overloads Shared Sub Main()
        Main(System.Environment.GetCommandLineArgs())
    End Sub

    Private Overloads Shared Sub Main(ByVal args() As String)
        Application.EnableVisualStyles()
        Application.Run(New Form1())
    End Sub

    Private WithEvents FirstNameBox, LastNameBox As TextBox
    Private WithEvents ValidateButton As Button
    Private FlowLayout1 As FlowLayoutPanel

    Private Sub New()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        ' Turn off validation when a control loses focus. This will be inherited by child
        ' controls on the form, enabling us to validate the entire form when the 
        ' button is clicked instead of one control at a time.
        Me.AutoValidate = System.Windows.Forms.AutoValidate.Disable

        FlowLayout1 = New FlowLayoutPanel()
        FlowLayout1.Dock = DockStyle.Fill

        FirstNameBox = New TextBox()
        FirstNameBox.Name = "FirstNameBox"
        FirstNameBox.Location = New Point(10, 10)
        FirstNameBox.Size = New Size(75, FirstNameBox.Size.Height)
        FirstNameBox.CausesValidation = True
        FlowLayout1.Controls.Add(FirstNameBox)

        LastNameBox = New TextBox()
        LastNameBox.Name = "LastNameBox"
        LastNameBox.Location = New Point(90, 10)
        LastNameBox.Size = New Size(75, LastNameBox.Size.Height)
        LastNameBox.CausesValidation = True
        FlowLayout1.Controls.Add(LastNameBox)

        ValidateButton = New Button()
        ValidateButton.Text = "Validate"
        ValidateButton.Location = New Point(170, 10)
        ValidateButton.Size = New Size(75, ValidateButton.Size.Height)
        FlowLayout1.Controls.Add(ValidateButton)

        Me.Text = "Test Validation"

        Me.Controls.Add(FlowLayout1)
    End Sub


    Private Sub FirstNameBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles FirstNameBox.Validating
        If FirstNameBox.Text.Length = 0 Then
            e.Cancel = True
        Else
            e.Cancel = False
        End If
    End Sub


    Private Sub LastNameBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles LastNameBox.Validating
        e.Cancel = False
    End Sub


    Private Sub ValidateButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ValidateButton.Click
        If ValidateChildren() Then
            MessageBox.Show("Validation succeeded!")
        Else
            MessageBox.Show("Validation failed.")
        End If
    End Sub
End Class

설명

컨트롤 사용자는 Windows Forms 컨트롤에서 포커스를 전환 하는 경우 사용할지 AutoValidate 해당 데이터의 유효성을 검사 하는 방법을 결정 합니다.If a user switches focus off of a Windows Forms control, the control will use AutoValidate to determine how to validate its data. 애플리케이션 개발자에 대 한 명시적 호출을 수행 하지 않고 발생 하므로이 형식의 유효성 검사 암시적 유효성 검사가 이라고 Validate 또는 ValidateChildren합니다.This type of validation is called implicit validation, because it occurs without the application developer having to make an explicit call to Validate or ValidateChildren.

이 값에 해당 하는 속성을 컨트롤의 유형에 따라 다른 기본값 해야 합니다.The property corresponding to this value will have different defaults based on the type of control. 자세한 내용은 Windows Forms에서 사용자 입력 유효성 검사합니다.For more information, see User Input Validation in Windows Forms.

적용 대상

추가 정보