Define your own dialog box and get user input : 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.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
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
6.Microsoft.Win32.OpenFileDialog/SaveFileDialog
7.Get a list of files from a folder based on the result of a FolderBrowserDialog
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.