Answer to Question #339819 in C# for asha

Question #339819

1.Write a code to close the curent form and show second form?



2.Write a code that raise an event after 10second,in event display your complete name using messageBox.



3.Supose you have a form that has one Button,when you click on Button,yoy should display a OpenDialogBox.When OpenDialogBox is open,if user click on Button,Show Message that you click on ok button.If user click cancel button,show messgae that yo click on cancel button.

1
Expert's answer
2022-05-14T16:42:24-0400
public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }


        private void EventButton_Click(object sender, EventArgs e)
        {
            Thread.Sleep(10000);
            MessageBox.Show("Bob(Your name)");
        }


        private void OpenDialogButton_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("", "", MessageBoxButtons.OKCancel);
            if (res == DialogResult.OK)
                MessageBox.Show("You click on ok button");
            if (res == DialogResult.Cancel)
                MessageBox.Show("You click on cancel button");


        }


        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            MainForm mainForm = new MainForm();
            mainForm.ShowDialog();
            this.Close();
        }


        private void ExitButton_Click(object sender, EventArgs e)
        {
            Environment.Exit(1);
        }
    }

    partial class MainForm
    {
        /// <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.EventButton = new System.Windows.Forms.Button();
            this.OpenDialogButton = new System.Windows.Forms.Button();
            this.ExitButton = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // EventButton
            // 
            this.EventButton.Location = new System.Drawing.Point(12, 21);
            this.EventButton.Name = "EventButton";
            this.EventButton.Size = new System.Drawing.Size(127, 30);
            this.EventButton.TabIndex = 1;
            this.EventButton.Text = "Raise an event";
            this.EventButton.UseVisualStyleBackColor = true;
            this.EventButton.Click += new System.EventHandler(this.EventButton_Click);
            // 
            // OpenDialogButton
            // 
            this.OpenDialogButton.Location = new System.Drawing.Point(12, 75);
            this.OpenDialogButton.Name = "OpenDialogButton";
            this.OpenDialogButton.Size = new System.Drawing.Size(127, 30);
            this.OpenDialogButton.TabIndex = 2;
            this.OpenDialogButton.Text = "Open Dialog";
            this.OpenDialogButton.UseVisualStyleBackColor = true;
            this.OpenDialogButton.Click += new System.EventHandler(this.OpenDialogButton_Click);
            // 
            // ExitButton
            // 
            this.ExitButton.Location = new System.Drawing.Point(12, 125);
            this.ExitButton.Name = "ExitButton";
            this.ExitButton.Size = new System.Drawing.Size(127, 36);
            this.ExitButton.TabIndex = 3;
            this.ExitButton.Text = "Exit";
            this.ExitButton.UseVisualStyleBackColor = true;
            this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(161, 173);
            this.Controls.Add(this.ExitButton);
            this.Controls.Add(this.OpenDialogButton);
            this.Controls.Add(this.EventButton);
            this.Name = "MainForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Main";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
            this.ResumeLayout(false);


        }


        #endregion
        private System.Windows.Forms.Button EventButton;
        private System.Windows.Forms.Button OpenDialogButton;
        private System.Windows.Forms.Button ExitButton;
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS