ValidationConstraints 열거형

정의

컨테이너에 있는 자식 컨트롤의 유효성을 검사하는 방법에 대한 정보를 ValidateChildren(ValidationConstraints)에 알리는 상수를 정의합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class ValidationConstraints
[System.Flags]
public enum ValidationConstraints
[<System.Flags>]
type ValidationConstraints = 
Public Enum ValidationConstraints
상속
ValidationConstraints
특성

필드

Enabled 2

Enabled 속성이 true로 설정된 자식 컨트롤의 유효성을 검사합니다.

ImmediateChildren 16

컨테이너 내에서 직접 호스팅되는 자식 컨트롤의 유효성을 검사합니다. 이 자식 컨트롤의 자식에 대해서는 유효성을 검사하지 않습니다. 예를 들어, 사용자 지정 Form이 들어 있는 UserControl이 있고 이 UserControlButton이 들어 있는 경우, ImmediateChildren을 사용하면 ValidatingUserControl 이벤트는 발생하지만 ValidatingButton 이벤트는 발생하지 않습니다.

None 0

컨트롤 속성 설정에 관계없이 모든 자식 컨트롤과 이 자식 컨트롤의 모든 자식에 대해 유효성을 검사합니다.

Selectable 1

선택될 수 있는 자식 컨트롤의 유효성을 검사합니다.

TabStop 8

사용자가 Tab 키를 사용하여 해당 컨트롤로 이동할 수 있음을 나타내는 TabStop 값 집합을 갖는 자식 컨트롤의 유효성을 검사합니다.

Visible 4

Visible 속성이 true로 설정된 자식 컨트롤의 유효성을 검사합니다.

예제

다음 코드 예제에서는 하면 합니다 Validating 이벤트를 해당 폼의 직접 자식에 대해 발생 Enabled 속성은 true합니다.

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

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

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

        void Form1_Load(object sender, EventArgs e)
        {
            // Create controls on form.
            TextBox textBox1, textBox2, textBox3;
            FlowLayoutPanel flowPanel1;
            TextBox subTextBox1;
            Button button1;

            this.Size = new Size(500, 300);
            this.AutoValidate = AutoValidate.Disable;

            textBox1 = new TextBox();
            textBox1.Location = new Point(20, 20);
            textBox1.Size = new Size(75, textBox1.Size.Height);
            textBox1.CausesValidation = true;
            textBox1.Validating += new System.ComponentModel.CancelEventHandler(textBox1_Validating);
            this.Controls.Add(textBox1);

            textBox2 = new TextBox();
            textBox2.Location = new Point(105, 20);
            textBox2.Size = new Size(75, textBox2.Size.Height);
            textBox2.CausesValidation = true;
            textBox2.Validating += new System.ComponentModel.CancelEventHandler(textBox2_Validating);
            this.Controls.Add(textBox2);

            textBox3 = new TextBox();
            textBox3.Location = new Point(190, 20);
            textBox3.Size = new Size(75, textBox3.Size.Height);
            textBox3.Enabled = false;
            textBox3.CausesValidation = true;
            textBox3.Validating += new System.ComponentModel.CancelEventHandler(textBox3_Validating);
            this.Controls.Add(textBox3);

            button1 = new Button();
            button1.Text = "Click";
            button1.Location = new Point(270, 20);
            button1.Click += new EventHandler(button1_Click);
            this.Controls.Add(button1);

            flowPanel1 = new FlowLayoutPanel();
            flowPanel1.Size = new Size(400, 100);
            flowPanel1.Dock = DockStyle.Bottom;
            subTextBox1 = new TextBox();
            subTextBox1.CausesValidation = true;
            subTextBox1.Validating += new System.ComponentModel.CancelEventHandler(subTextBox1_Validating);
            flowPanel1.Controls.Add(subTextBox1);
            this.Controls.Add(flowPanel1);
        }

        void subTextBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MessageBox.Show("subTextBox1 Validating!");
        }

        void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MessageBox.Show("textBox1 Validating!");
        }

        void textBox2_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MessageBox.Show("textBox2 Validating!");
        }

        void textBox3_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MessageBox.Show("textBox3 Validating!");
        }

        void button1_Click(object sender, EventArgs e)
        {
            this.ValidateChildren(ValidationConstraints.ImmediateChildren | ValidationConstraints.Enabled);
        }
    }
}
Imports System.Drawing
Imports System.Windows.Forms

Namespace ValidateChildrenWithConstraints
    _
    Class Form1
        Inherits Form

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

        Private Sub New()
            AddHandler Me.Load, AddressOf Form1_Load
        End Sub

        Dim WithEvents TextBox1, TextBox2, TextBox3 As TextBox
        Dim FlowPanel1 As FlowLayoutPanel
        Dim WithEvents SubTextBox1 As TextBox
        Dim WithEvents Button1 As Button

        Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' Create controls on form.

            Me.Size = New Size(500, 300)
            Me.AutoValidate = AutoValidate.Disable

            TextBox1 = New TextBox()
            TextBox1.Location = New Point(20, 20)
            TextBox1.Size = New Size(75, TextBox1.Size.Height)
            TextBox1.CausesValidation = True
            Me.Controls.Add(TextBox1)

            TextBox2 = New TextBox()
            TextBox2.Location = New Point(105, 20)
            TextBox2.Size = New Size(75, TextBox2.Size.Height)
            TextBox2.CausesValidation = True
            Me.Controls.Add(TextBox2)

            TextBox3 = New TextBox()
            TextBox3.Location = New Point(190, 20)
            TextBox3.Size = New Size(75, TextBox3.Size.Height)
            TextBox3.Enabled = False
            TextBox3.CausesValidation = True
            Me.Controls.Add(TextBox3)

            Button1 = New Button()
            Button1.Text = "Click"
            Button1.Location = New Point(270, 20)
            Me.Controls.Add(Button1)

            FlowPanel1 = New FlowLayoutPanel()
            FlowPanel1.Size = New Size(400, 100)
            FlowPanel1.Dock = DockStyle.Bottom
            SubTextBox1 = New TextBox()
            SubTextBox1.CausesValidation = True
            FlowPanel1.Controls.Add(SubTextBox1)
            Me.Controls.Add(FlowPanel1)
        End Sub


        Sub SubTextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SubTextBox1.Validating
            MessageBox.Show("SubTextBox1 Validating!")
        End Sub


        Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
            MessageBox.Show("TextBox1 Validating!")
        End Sub


        Sub TextBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
            MessageBox.Show("TextBox2 Validating!")
        End Sub


        Sub TextBox3_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox3.Validating
            MessageBox.Show("TextBox3 Validating!")
        End Sub


        Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
            Me.ValidateChildren((ValidationConstraints.ImmediateChildren Or ValidationConstraints.Enabled))
        End Sub
    End Class
End Namespace 'ValidateChildrenWithConstraints

설명

기본적으로 ValidateChildren 폼 같은 컨테이너에서 사용 가능한 모든 컨트롤의 유효성을 검사 합니다. 이 열거형을 사용 하 여 컨트롤의 형식을 제한 된 Validating 이벤트가 발생 합니다.

비트 OR 연산 함께 이러한 열거 값을 결합할 수 있습니다. 비트 OR 연산자를 사용 하 여 매개 변수를 결합 하면 논리적 AND 연산을 줄어듭니다. 예를 들어, 호출 ValidateChildren(ValidationConstraints.ImmediateChildren | ValidationConstraints.Enabled) 만 발생 시킵니다는 Validating 컨테이너의 직계 자식이 고 사용 하는 컨트롤의 이벤트입니다.

호출할 때 ImmediateChildren를 지정 하지 않으면 ValidateChildren, 컨트롤 계층 구조에서 모든 자식 컨트롤의 유효성을 검사 하는 메서드가 필요 합니다.

적용 대상

추가 정보