Define your own dialog box and get user input : Dialog « GUI Windows Form « C# / C Sharp

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. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » GUI Windows Form » DialogScreenshots 
Define your own dialog box and get user input
Define your own dialog box and get user input

  using System;
  using System.Resources;
  using System.Drawing;
  using System.Collections;
  using System.Windows.Forms;
  using System.Resources;

  class Test
  {
    static void Main(string[] args)
    {
      SomeCustomForm myForm = new SomeCustomForm();
      myForm.Message = "Message";

      myForm.ShowDialog(new Form());

      if(myForm.DialogResult == DialogResult.OK)
      {
        Console.WriteLine(myForm.Message);
      }
    }
  }
    
    public class SomeCustomForm : System.Windows.Forms.Form
    {
        private System.ComponentModel.Container components;
    private System.Windows.Forms.Button btnCancel;
    private System.Windows.Forms.Button btnOK;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox txtMessage;

        public SomeCustomForm()
        {
            InitializeComponent();
      this.StartPosition = FormStartPosition.CenterParent;      
        }

    private string strMessage;

    public string Message
    {
      getreturn strMessage;}
      set
      
        strMessage = value;
        txtMessage.Text = strMessage;
      }
    }


    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }


    #region Windows Form Designer generated code
        private void InitializeComponent()
    {
      this.components = new System.ComponentModel.Container ();
      this.label1 = new System.Windows.Forms.Label ();
      this.btnOK = new System.Windows.Forms.Button ();
      this.btnCancel = new System.Windows.Forms.Button ();
      this.txtMessage = new System.Windows.Forms.TextBox ();
      label1.Location = new System.Drawing.Point (128);
      label1.Text = "Type in your message.";
      label1.Size = new System.Drawing.Size (24048);
      label1.TabIndex = 1;

      btnOK.Location = new System.Drawing.Point (16104);
      btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
      btnOK.Size = new System.Drawing.Size (9624);
      btnOK.TabIndex = 2;
      btnOK.Text = "OK";
      btnOK.Click += new System.EventHandler (this.btnOK_Click);
      btnCancel.Location = new System.Drawing.Point (152104);
      btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
      btnCancel.Size = new System.Drawing.Size (9624);
      btnCancel.TabIndex = 3;
      btnCancel.Text = "Cancel";
      txtMessage.Location = new System.Drawing.Point (1672);
      txtMessage.TabIndex = 0;
      txtMessage.Size = new System.Drawing.Size (23220);
      this.Text = "Some Custom Dialog";
      this.MaximizeBox = false;
      this.AutoScaleBaseSize = new System.Drawing.Size (513);
      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
      this.ControlBox = false;
      this.MinimizeBox = false;
      this.ClientSize = new System.Drawing.Size (266151);
      this.Controls.Add (this.btnCancel);
      this.Controls.Add (this.btnOK);
      this.Controls.Add (this.label1);
      this.Controls.Add (this.txtMessage);
    }
    #endregion

    protected void btnOK_Click (object sender, System.EventArgs e)
    {
      // OK button clicked.
      // get new message.
      strMessage = txtMessage.Text;
    }
    }  


           
       
Related examples in the same category
1. A dialog by user defined property
2. Color Fill dialog
3. Color Scroll Dialog Box
4. Italic User Message Dialog: your own dialog
5. Use DialogResult property in Form
w___w__w_._j_a___v___a___2s.c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.