Well, I did two windows

The First Windows for the game
And the secend window for the name of the game, CANCEL button PLAY button

accidentally done now in FORM1 the game and the FORM2 post opening which of course does open before the FORM1 So I ask if There is a way to reverse it (i mean to open before the FORM2) Thanks.


and 1 more quastion:

How can i make this?? = PICTUREBOX1 I move the mouse on the image and it show PICTUREBOX2

Technically you can change the primarily loaded form to your "FORM2" form simply by changing the entry point in your program.

In Program.cs (assuming you left everything with default names as it seems you did) you should see:

static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

Really not a huge issue to change that to new Form2() instead. Potential problem is that depending how you've got your forms set up this may cause a bit of an issue with navigation between your code segments as form2 becomes the parent form and form2 then needs to be 'called' into existance later on.

On a side note, particularly for larger programs, always a good idea to name components according to their use with a consistant naming convention throughout your program. Makes it easier to work with code and debug if needed. All references can be obfuscated later but in development it makes things go much smoother overall.

Hope this helps :) Sorry I couldn't get to your 2nd question. Please remember to mark as solved once your issue is resolved.

Edited to make it more colourful and point out things that may have been harder to read in black and white :)

where i should put the code?? in Form1 or Form2?

Which code?

For the second problem, btw, you just need the MouseHover and MouseLeave events for the picturebox, changing the background image to picture2 on MouseHover and changing it back on MouseLeave.

Personally I think you should put the code wherever you like since you didn't bother reading my post :twisted:

As I said above:
In Program.cs (assuming you left everything with default names as it seems you did) you should see: And I wouldn't just go changing the code around without first looking into your application to ensure that changing FORM2 to the primary form won't have additional unpleasant effects on the rest of your code.

its work thanks.. but 1 more quastion (soory):

i did this:

Form1 ABC = new Form1();
ABC.Show();

and its also work but i want that when i click the button he will open the FORM2 and close FORM1

so how am i do that? thanks again and soory

Same way you did above works for opening form2 and you use the .Close() operator to close the form you no longer need (after you've opened another form, not before hand).

What you are creating here is a parent child relationship between the two forms.
When you create Form2 WITHIN Form1, Form2 is the child, Form1 is the parent.
A word of Caution; whilst creating a child form then closing the parent form will often work...it is not good design practice and it wont ALWAYS work. The main exception being if the parent form is also your main application form; if you close that form your application will close!
It is much better to hide the parent when you show the child. If you never intend to redisplay the parent then you can create an event handler which will close the parent when the child closes:

private void OpenForm2()
        {
            Form2 frm2 = new Form2();
            frm2.FormClosed += new FormClosedEventHandler(frm2_FormClosed);
            frm2.Show();
            this.Hide();
        }
 
              
        private void frm2_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Close();
        }

It is much better to hide the parent when you show the child. If you never intend to redisplay the parent then you can create an event handler which will close the parent when the child closes

Oddly enough this is what I was thinking but, having just woken up, my brain wouldn't let me translate it into a proper forum reply :twisted: Good catch though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.