MaskedTextBox.CausesValidation : MaskedTextBox « System.Windows.Forms « C# / C Sharp by API

Home
C# / C Sharp by API
1.Microsoft.Win32
2.System
3.System.Collections
4.System.Collections.Generic
5.System.Collections.Specialized
6.System.ComponentModel
7.System.Configuration
8.System.Data
9.System.Data.Common
10.System.Data.Linq
11.System.Data.Odbc
12.System.Data.OleDb
13.System.Data.Sql
14.System.Data.SqlClient
15.System.Diagnostics
16.System.DirectoryServices
17.System.Drawing
18.System.Drawing.Drawing2D
19.System.Drawing.Imaging
20.System.Drawing.Printing
21.System.Drawing.Text
22.System.EnterpriseServices
23.System.Globalization
24.System.IO
25.System.IO.Compression
26.System.IO.IsolatedStorage
27.System.IO.Ports
28.System.Linq
29.System.Management
30.System.Media
31.System.Messaging
32.System.Net
33.System.Net.Mail
34.System.Net.NetworkInformation
35.System.Net.Sockets
36.System.Reflection
37.System.Resources
38.System.Runtime
39.System.Runtime.CompilerServices
40.System.Runtime.InteropServices
41.System.Runtime.Remoting
42.System.Runtime.Remoting.Channels
43.System.Runtime.Remoting.Channels.Http
44.System.Runtime.Remoting.Messaging
45.System.Runtime.Serialization
46.System.Runtime.Serialization.Formatters.Binary
47.System.Runtime.Serialization.Formatters.Soap
48.System.Security
49.System.Security.AccessControl
50.System.Security.Cryptography
51.System.Security.Cryptography.X509Certificates
52.System.Security.Permissions
53.System.Security.Policy
54.System.Security.Principal
55.System.ServiceProcess
56.System.Text
57.System.Text.RegularExpressions
58.System.Threading
59.System.Timers
60.System.Web.Security
61.System.Web.Services
62.System.Windows.Controls
63.System.Windows.Forms
64.System.Xml
65.System.Xml.Linq
66.System.Xml.Schema
67.System.Xml.Serialization
68.System.Xml.XPath
69.System.Xml.Xsl
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp by API » System.Windows.Forms » MaskedTextBox 
MaskedTextBox.CausesValidation
 


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

public class MainWindow : Form {
    public MainWindow() {
        InitializeComponent();
        CreateLabelControl();
    }

    private void btnDisplayData_Click(object sender, EventArgs e) {
        string textBoxData = "";
        textBoxData += string.Format("MultiLine:  {0}\n", txtMultiline.Text);
        textBoxData += string.Format("\nPassword:  {0}\n", txtPassword.Text);
        textBoxData += string.Format("\nUppercase:  {0}\n", txtUpperCase.Text);
        textBoxData += string.Format("\nMasked:  {0}\n", txtMaskedTextBox.Text);

        MessageBox.Show(textBoxData, "Here is the data in your TextBoxes");
    }

    private void CreateLabelControl() {
        Label lblInstructions = new Label();
        lblInstructions.Text = "Please enter values in all the text boxes";
        lblInstructions.Font = new Font("Times New Roman"9.75F, FontStyle.Bold);
        lblInstructions.AutoSize = true;
        lblInstructions.Location = new System.Drawing.Point(1613);
        lblInstructions.Size = new System.Drawing.Size(24016);
        this.Controls.Add(lblInstructions);
    }

    private void txtMaskedTextBox_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) {
        this.Text = string.Format("Error: {0}", e.RejectionHint);
    }

    private void txtMaskedTextBox_KeyDown(object sender, KeyEventArgs e) {
        this.Text = "Labels and TextBoxes";
    }
    private void InitializeComponent() {
        this.lblPassword = new System.Windows.Forms.Label();
        this.txtPassword = new System.Windows.Forms.TextBox();
        this.lblMultiline = new System.Windows.Forms.Label();
        this.txtMultiline = new System.Windows.Forms.TextBox();
        this.lblUpperCaseOnly = new System.Windows.Forms.Label();
        this.txtUpperCase = new System.Windows.Forms.TextBox();
        this.lblMaskedTextBox = new System.Windows.Forms.Label();
        this.txtMaskedTextBox = new System.Windows.Forms.MaskedTextBox();
        this.btnDisplayData = new System.Windows.Forms.Button();
        this.SuspendLayout();

        this.lblPassword.AutoSize = true;
        this.lblPassword.Location = new System.Drawing.Point(1343);
        this.lblPassword.Name = "lblPassword";
        this.lblPassword.Size = new System.Drawing.Size(9413);
        this.lblPassword.TabIndex = 0;
        this.lblPassword.Text = "&Password TextBox:";

        this.txtPassword.Location = new System.Drawing.Point(12543);
        this.txtPassword.Name = "txtPassword";
        this.txtPassword.PasswordChar = '*';
        this.txtPassword.Size = new System.Drawing.Size(22020);
        this.txtPassword.TabIndex = 1;

        this.lblMultiline.AutoSize = true;
        this.lblMultiline.Location = new System.Drawing.Point(1480);
        this.lblMultiline.Name = "lblMultiline";
        this.lblMultiline.Size = new System.Drawing.Size(8613);
        this.lblMultiline.TabIndex = 2;
        this.lblMultiline.Text = "&Multiline TextBox:";

        this.txtMultiline.Location = new System.Drawing.Point(12580);
        this.txtMultiline.Multiline = true;
        this.txtMultiline.Name = "txtMultiline";
        this.txtMultiline.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
        this.txtMultiline.Size = new System.Drawing.Size(22052);
        this.txtMultiline.TabIndex = 3;

        this.lblUpperCaseOnly.AutoSize = true;
        this.lblUpperCaseOnly.Location = new System.Drawing.Point(15157);
        this.lblUpperCaseOnly.Name = "lblUpperCaseOnly";
        this.lblUpperCaseOnly.Size = new System.Drawing.Size(8213);
        this.lblUpperCaseOnly.TabIndex = 4;
        this.lblUpperCaseOnly.Text = "&Uppercase Only:";

        this.txtUpperCase.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
        this.txtUpperCase.Location = new System.Drawing.Point(125157);
        this.txtUpperCase.Name = "txtUpperCase";
        this.txtUpperCase.Size = new System.Drawing.Size(22020);
        this.txtUpperCase.TabIndex = 5;
        // 
        this.lblMaskedTextBox.AutoSize = true;
        this.lblMaskedTextBox.Location = new System.Drawing.Point(15199);
        this.lblMaskedTextBox.Name = "lblMaskedTextBox";
        this.lblMaskedTextBox.Size = new System.Drawing.Size(8313);
        this.lblMaskedTextBox.TabIndex = 7;
        this.lblMaskedTextBox.Text = "Mas&ked TextBox";
        // 
        this.txtMaskedTextBox.BeepOnError = true;
        this.txtMaskedTextBox.CausesValidation = false;
        this.txtMaskedTextBox.Location = new System.Drawing.Point(125199);
        this.txtMaskedTextBox.Mask = "(999) 000-0000";
        this.txtMaskedTextBox.Name = "txtMaskedTextBox";
        this.txtMaskedTextBox.Size = new System.Drawing.Size(22020);
        this.txtMaskedTextBox.TabIndex = 8;
        this.txtMaskedTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMaskedTextBox_KeyDown);
        this.txtMaskedTextBox.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.txtMaskedTextBox_MaskInputRejected);
        // 
        this.btnDisplayData.Location = new System.Drawing.Point(257236);
        this.btnDisplayData.Name = "btnDisplayData";
        this.btnDisplayData.Size = new System.Drawing.Size(8823);
        this.btnDisplayData.TabIndex = 6;
        this.btnDisplayData.Text = "Display Data";
        this.btnDisplayData.Click += new System.EventHandler(this.btnDisplayData_Click);
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(357276);
        this.Controls.Add(this.txtMaskedTextBox);
        this.Controls.Add(this.lblMaskedTextBox);
        this.Controls.Add(this.btnDisplayData);
        this.Controls.Add(this.txtUpperCase);
        this.Controls.Add(this.lblUpperCaseOnly);
        this.Controls.Add(this.txtMultiline);
        this.Controls.Add(this.lblMultiline);
        this.Controls.Add(this.txtPassword);
        this.Controls.Add(this.lblPassword);
        this.Text = "Fun with Labels and TextBoxes";
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    private System.Windows.Forms.Label lblPassword;
    private System.Windows.Forms.TextBox txtPassword;
    private System.Windows.Forms.Label lblMultiline;
    private System.Windows.Forms.TextBox txtMultiline;
    private System.Windows.Forms.Label lblUpperCaseOnly;
    private System.Windows.Forms.TextBox txtUpperCase;
    private System.Windows.Forms.Label lblMaskedTextBox;
    private System.Windows.Forms.MaskedTextBox txtMaskedTextBox;
    private System.Windows.Forms.Button btnDisplayData;

    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new MainWindow());
    }
}

   
  
Related examples in the same category
1.MaskedTextBox.BeepOnError
2.MaskedTextBox.KeyDown
3.MaskedTextBox.MaskInputRejected
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.