A dialog by user defined property : Dialog « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » DialogScreenshots 
A dialog by user defined property
 

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

class MainClass {
    public static void Main() {
        Phone frm = new Phone();
        while (true) {
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK) {
                Console.WriteLine(frm.PhoneNumber);
                if (frm.PhoneNumber.Length == | frm.PhoneNumber.Length == 12) {
                    break;
                else {
                    MessageBox.Show("Phone number was not formatted correctly. Please correct entry.");
                }
            else if (frm.DialogResult == DialogResult.Cancel) {
                Console.WriteLine("Form was canceled.");
                break;
            }
        }
        frm.Close();
    }
}
class Phone : Form {
    private System.Windows.Forms.TextBox textBox1  = new System.Windows.Forms.TextBox();
    private System.Windows.Forms.Label label1 = new System.Windows.Forms.Label() ;
    private System.Windows.Forms.Button btnOK = new System.Windows.Forms.Button();
    private System.Windows.Forms.Button btnCancel = new System.Windows.Forms.Button();

    public Phone() {
        this.SuspendLayout();

        this.textBox1.Location = new System.Drawing.Point(12221);
        this.textBox1.Margin = new System.Windows.Forms.Padding(1333);
        this.textBox1.Size = new System.Drawing.Size(11520);

        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(1026);
        this.label1.Margin = new System.Windows.Forms.Padding(3313);
        this.label1.Size = new System.Drawing.Size(11014);
        this.label1.Text = "Enter phone number:";
        this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

        this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
        this.btnOK.Location = new System.Drawing.Point(3665);
        this.btnOK.Text = "OK";

        this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        this.btnCancel.Location = new System.Drawing.Point(13265);
        this.btnCancel.Text = "Cancel";
        this.ClientSize = new System.Drawing.Size(270107);
        this.Controls.Add(this.btnCancel);
        this.Controls.Add(this.btnOK);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.textBox1);
        this.ResumeLayout(false);
        this.PerformLayout();
        btnOK.DialogResult = DialogResult.OK;
        btnCancel.DialogResult = DialogResult.Cancel;
    }
    public string PhoneNumber {
        get return textBox1.Text; }
        set textBox1.Text = value; }
    }
}

 
Related examples in the same category
1.Color Fill dialog
2.Color Scroll Dialog Box
3.Italic User Message Dialog: your own dialog
4.Use DialogResult property in Form
5.Define your own dialog box and get user inputDefine your own dialog box and get user input
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.