Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6151481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:46:28+00:00 2026-05-23T19:46:28+00:00

I have c# form1 with random numbers created and show those numbers in form2,

  • 0

I have c# form1 with random numbers created and show those numbers in form2, and I again create new random numbers in form1, and when I try to show form2 for the secnd time I have seen the first time created numbers not the second time ( the data in form2 are not changed). I would appreciate If some one can help. The code for form1 and form2 are:

//form1
public static int var2;
Form secondForm = new Form2();

private void Form1_Load(object sender, EventArgs e)
{
  var2 = RandomNumber(1, 50);
  secondForm.Show();
  secondForm.Refresh();
  Thread.Sleep(2000);
  secondForm.Hide();
  var2 = RandomNumber(1, 50);
  secondForm.Show();
  secondForm.Refresh();
}
private int RandomNumber(int min, int max)
{
  Random random = new Random();
  return random.Next(min, max);
}
//form2
private void Form2_Load(object sender, EventArgs e)
{
  this.Invoke(new EventHandler(DisplayText1));
}
private void DisplayText1(object sender, EventArgs e)
{
  textBox1.AppendText("    ");
  textBox1.AppendText(Form1.var2.ToString());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:46:29+00:00Added an answer on May 23, 2026 at 7:46 pm

    You are reusing the same form when you do the 2nd “secondForm.Show();”. When you call Hide/Show all you are doing is making the form visible/invisible. To confirm this, try setting a breakpoint in Form2_Load, and see how many times it is hit.

    If you put the following:

    secondForm = new Form2();
    

    After the 2nd call to RandomNumber(1,50), you will get different #s.

    Hope this helps,

    John

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Form1 I have PageControl. At run time my program creates tab sheets. In
if i have mediaplayer1 in Form1 and mediaplayer2 in Form2 than how can i
I have 3 forms in my project form1 , form2 , form3 and it
i have a prioblem with a callback because my Form1 open Form2 and send
if i have two media players in form1 and form2 respectively....how can i control
Let say I have are two WPF forms: Form1 and Form2 . Form1 contains
I have application in VB.net that have two different form (Form1 and Form2). Now
I have a remote php program that generates 2 random numbers, I call to
I am creating a custom captcha where random numbers are generated and you have
My form receives asynchronous callbacks from another object on random worker threads. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.