Skip to main content

Conformation MessageBox

This BLOG POST demonstrate how to use the MessageBox result in window form programming. to full fill this task we will depend on DialogResult  property in Windows Forms.. 



               when we are doing windows programming using Csharp ,to show the intermediate result  we will display by messageBox
MessgeBox is having one main  function show .it returns DialogResult Value.when user used MessgeBox to display the data,user has to click default buttons OK,cancel,Abort,Ignore etc to close MessgeBox.
this we can get from MessgeBox and it will be saved in DialogResult variable .
DialogResult is consist different button values using ENUM data types .
Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
·         Microsoft Visual Studio .NET or Microsoft Visual Studio 2005 or above
This article assumes that you are familiar with the following topics:
·         Windows application programming
·          Visual C#.net


Creating Window Form and showing Conformation Result
This sample uses the MessgeBox to determine the button that you should click to give the conformation.

1.     Create a new Windows Application project in Visual C# .NET. By default, Form1 is added to the project.
2.     In the Design window of Form1, add a Button control. change the Text property to ARE U READY TO LEARN..
3.     Add the following code to the button1_Click event procedure:
           
private void button1_Click(object sender, EventArgs e)
        {
           DialogResult result=
MessageBox.Show("press  ok or cancel", "conformation",
                                                 MessageBoxButtons. OKCancel  );
           if (result == DialogResult.OK)    { MessageBox.Show("u selected OK"); }
              else                                      { MessageBox.Show("u selected Cancel"); }
       }
This displays user Conformation in another MessageBox, based on Yesno Options, and message box is displayed with the details of the button that the user clicked.


Complete Code Listing
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{

    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(47, 34);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(187, 55);
            this.button1.TabIndex = 0;
            this.button1.Text = "ARE U READY TO LEARN..";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new                                                      System.EventHandler(this.button1_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new
                     System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode =                                                                                     System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 133);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "TECHKEYS";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button button1;
    }





    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }





        private void button1_Click(object sender, EventArgs e)
        {
           DialogResult result= MessageBox.Show
                           ("Think and select ...","conformation",
                                MessageBoxButtons.YesNo);
           if (result == DialogResult.Yes )
           { MessageBox.Show("FALLOW TECHKEYS blog....."); }
           else
           { MessageBox.Show("LEARNING IS EARNING...."); }
          
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }
    }
}


Verify That It Works
1.     Press CTRL+F5 to run the project. Form1 is displayed.
2.     Click on ARE U READY TO LEARN..button.
3.     To Conform, click either Yes or NO. A message appears with the details of the button that you clicked.
·         If you clicked Yes, the following caption appears:
FALLOW TECHKEYS blog.....
·         If you clicked NO, the following caption appears:
LEARNING IS EARNING...



output will be 







http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=

Comments

Popular posts from this blog

FAQS on DOTNET

Hello to every one who are fallowing my blog, today i attend one call from one Technical Recruiter (name is not required i think ) he asked some couple of question...ok i answered ....mean while  he asked one question (in my life never i feel it is relevant  for developer) who will use oops development environment? ha.. ha.. expect answer and update  to me   So far we received many request for FAQs on CSHARP, ASP.NET AND SQLSERVER for fresher who are in finishing schools. We are actively working with these Technologies  to bring   KEY   Resources for   TECHIES.                                   you are interested in helping others  bring  TECHKEYS   to your Friends through Social Media, please Leave the Comment to us to improve our work and subscribe  for more information .   Q 1) levels of nesting in a subq...

SQLSERVER Functions- Coalesce()

SQL  Server  built-in functions Coalesce() It is A function Is Very Much Useful at Run time When We Have Multi Value Attribute in a Table. If U Consider below facts placed in a employee table With Id, Name, ph_no, Alt_no, Office no. id Name Ph_ no Alt_ no Office no 101 Albert 999999 456453 321333 102 khan null null 123455 103 victor 112121 null null 104 lovely null null 1897321 Above Employee table may have single value are three values if it have single value then it fill null  values with remaining attributes When We Retrieve The Number from employee table That Number Should Not be Null value To get not null value from employee table We Use Coalesce() Function It Returns First Encountered Not Null Value  from employee table select id , name , coalesce ( Ph_no , Alt_no , Office_no ) as contact...

OOPS-Constructors and distractor

Hi friends today we will discussed about constructors and distractor in csharp Constructors are used to memory allocation for real world entities which are created with the help of objects. When program or application is running, application required memory to save and manipulate data of that real world object/entities. Now the question is how much memory is required for that object? Frankly no one can decide how much memory is required for that application because of that all object oriented programming languages depends on heap memory. Heap memory is a logical memory in RAM (temporary memory) and size is logically infinity (physically it is limited).This memory has to be creating at run time when we are using object in our program/application. Now we have to know that what type of data members we have in object. In object we have two types of data members’ object instance  shared instance Object instance are allocated occupies object memory and...