Dialogbox in C#.NET. How to create a dialog box using c# or any .NET language.

DIALOGBOX C# DIALOG BOX

C# Tutorials

  

DIALOGBOX C# DIALOG BOX

Learn Tutorials
Dialogbox in C#.NET. How to create a dialog box using c# or any .NET language.

Example code for Dialogbox C# dialog box:
Basic dialog box usage:


RenameDlg rd=new RenameDlg();
rd.SetText(mainTabControl.SelectedTab.Text);
if(rd.ShowDialog(this)==DialogResult.OK)
   mainTabControl.SelectedTab.Text=rd.GetNameEntered();



========================================================
using System;
using System.Windows.Forms;

namespace TextSorter
{
   /// <summary>
   /// Summary description for RenameDlg.
   /// </summary>
   public class RenameDlg : Form
   {
      private System.Windows.Forms.TextBox nametextBox;
      private System.Windows.Forms.Button applyButton;
      private System.Windows.Forms.Button cancelButton;
      private System.Windows.Forms.Label label1;

      private void InitializeComponent()
      {
         this.nametextBox = new System.Windows.Forms.TextBox();
         this.label1 = new System.Windows.Forms.Label();
         this.applyButton = new System.Windows.Forms.Button();
         this.cancelButton = new System.Windows.Forms.Button();
         this.SuspendLayout();
         //
         // nametextBox
         //
         this.nametextBox.Location = new System.Drawing.Point(64, 4);
         this.nametextBox.Name = "nametextBox";
         this.nametextBox.Size = new System.Drawing.Size(168, 20);
         this.nametextBox.TabIndex = 0;
         this.nametextBox.Text = "";
         //
         // label1
         //
         this.label1.Location = new System.Drawing.Point(4, 8);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(68, 23);
         this.label1.TabIndex = 1;
         this.label1.Text = "Tab Name:";
         //
         // applyButton
         //
         this.applyButton.Location = new System.Drawing.Point(44, 32);
         this.applyButton.Name = "applyButton";
         this.applyButton.TabIndex = 2;
         this.applyButton.Text = "Apply";
         this.applyButton.Click += new System.EventHandler(this.applyButton_Click);
         //
         // cancelButton
         //
         this.cancelButton.Location = new System.Drawing.Point(124, 32);
         this.cancelButton.Name = "cancelButton";
         this.cancelButton.TabIndex = 3;
         this.cancelButton.Text = "Cancel";
         //
         // RenameDlg
         //
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(244, 61);
         this.Controls.Add(this.cancelButton);
         this.Controls.Add(this.applyButton);
         this.Controls.Add(this.nametextBox);
         this.Controls.Add(this.label1);
         this.Name = "RenameDlg";
         this.Text = "Rename Tab";
         this.ResumeLayout(false);

      }
   
      
      
      public RenameDlg()
      {
      
         InitializeComponent();
         //
         // TODO: Add constructor logic here
         //
         this.AcceptButton=applyButton;
         this.CancelButton=cancelButton;
         this.AcceptButton.DialogResult=DialogResult.OK;
      }
      
      public void SetText(string currentName)
      {
         this.nametextBox.Text=currentName;
      }
      
      public string GetNameEntered()
      {
         return nametextBox.Text;
      }

      private void applyButton_Click(object sender, System.EventArgs e)
      {
         Close();
      }

   }
}
This is example code for dialogbox in c#.net. how to create a dialog box using c# or any .net language.