Navneet Nayak

Navneet Nayak

  • NA
  • 27
  • 2.3k

reloading a form

Nov 16 2016 9:45 AM
Here my doubt is in Button6_click.
while clicking in button6 a messagebox appear, if i click on ''OK'', it should clear all the textbox items and picturebox items and reload the form again to play it again.
In my case the form hangs after clicking on ""ok"" button in the messagebox. 
 
 
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace lottery_song_selector
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
textBox1_songname.Text = ("sorry!!but he is my friend now");
pictureBox2_anil.Visible = true;
pictureBox1_bill.Visible = false;
pictureBox1_mark.Visible = false;
pictureBox1_mukesh.Visible = false;
pictureBox3_srk.Visible = false;
pictureBox4_navneet.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1_songname.Text = ("He is a old man");
pictureBox1_bill.Visible = true;
pictureBox1_mark.Visible = false;
pictureBox1_mukesh.Visible = false;
pictureBox2_anil.Visible = false;
pictureBox3_srk.Visible = false;
pictureBox4_navneet.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1_songname.Text = ("He has borrowed $2bn from Navneet");
pictureBox1_mark.Visible = true;
pictureBox1_bill.Visible = false;
pictureBox1_mukesh.Visible = false;
pictureBox2_anil.Visible = false;
pictureBox3_srk.Visible = false;
pictureBox4_navneet.Visible = false;
}
private void button4_Click(object sender, EventArgs e)
{
textBox1_songname.Text = ("He is Khan and he is a terorrist");
pictureBox3_srk.Visible = true;
pictureBox1_mukesh.Visible = false;
pictureBox1_bill.Visible = false;
pictureBox1_mark.Visible = false;
pictureBox2_anil.Visible = false;
pictureBox4_navneet.Visible = false;
}
private void button6_Click(object sender, EventArgs e)
{
textBox1_songname.Text =("Yes,You are right!!");
//textBox1_songname.Text = ("congratulation");
pictureBox4_navneet.Visible = true;
pictureBox1_mukesh.Visible = false;
pictureBox1_bill.Visible = false;
pictureBox1_mark.Visible = false;
pictureBox2_anil.Visible = false;
pictureBox3_srk.Visible = false;
DialogResult optn= MessageBox.Show("congratulation!!","Notification",MessageBoxButtons.OK,MessageBoxIcon.Information);
while (optn == DialogResult.OK)
{
textBox1_songname.Clear();
pictureBox1_bill.Hide();
pictureBox1_mark.Hide();
pictureBox1_mukesh.Hide(); //how to encapsulate all these functions in a single function
pictureBox2_anil.Hide();
pictureBox3_srk.Hide();
pictureBox4_navneet.Hide();
Form1_Load(this,new EventArgs());
}
}
private void button7_Click(object sender, EventArgs e)
{
textBox1_songname.Text = ("Please Try Again");
}
private void button8_Click(object sender, EventArgs e)
{
textBox1_songname.Text = ("Please update your knowledge");
pictureBox1_mukesh.Visible = true;
pictureBox1_bill.Visible = false;
pictureBox1_mark.Visible = false;
pictureBox2_anil.Visible = false;
pictureBox3_srk.Visible = false;
pictureBox4_navneet.Visible = false;
}
private void button3_clear_Click(object sender, EventArgs e)
{
textBox1_songname.Clear();
pictureBox1_bill.Hide();
pictureBox1_mark.Hide();
pictureBox1_mukesh.Hide();
pictureBox2_anil.Hide();
pictureBox3_srk.Hide();
pictureBox4_navneet.Hide();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
DialogResult result = MessageBox.Show("Are u sure want to play this game?", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
this.Show();
}
else
Application.Exit();
}
catch { }
}
private void button3_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button3_new_Click(object sender, EventArgs e)
{
this.Hide();
Form1 f = new Form1();
f.Show();
}
}
}

Answers (1)