Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Making a button help

So im currently working on a game project to create a basic tic tac toe game.

I've created my tic tac toe and done all the codings for it its working perfectly fine.

I have now added a seperate windows form (Form2) and i need help on how to link a button to the game? So when the user clicks "Start" on the button i want it to open the game.

Can someone help me with this basic line of coding ive been trying to figure it out ever since and i thought that people on this section of the forum can assist me ?
Uh...Do you just want to create a new instance of Form1? If so, it should be easy to google. Otherwise, you may need to elaborate.

riperino animefanerino
(Sep 12, 2016 04:11 PM){Nexus} Wrote:  If the FBI come knocking I'm gonna spew information out my ass about Aeon.

They'd have to tell me to stop giving them information.

(Mar 5, 2016 07:44 AM)Oliver Sykes Wrote:  Uh...Do you just want to create a new instance of Form1? If so, it should be easy to google. Otherwise, you may need to elaborate.

If it is what Oliver Sykes says ,

Lets say your form where your game actually is taken place is called formGame and your other form where you want to press start and open up formGame from (if it is that that you actually want to achieve)
is called formStart then,

On he buttonClick handler (button_Click) of formStart the code should be :

PHP Code

<?php 
formGame nameHowYouWant 
= new formGame ();
// nameHowYouWant .Show();
nameHowYouWant.ShowDialog(); 

The nameHowYouWant .Show(); shows the form in a non modal form. This means that you can still click on the parent form (formStart)

The nameHowYouWant.ShowDialog(); shows the form modally, meaning you cannot go or click the parent form untill you close formGame.

🤝
If you mean you need to press a button in Form2 to start the game in Form1, you can pass your Form1 onto the 2nd form like this:

Form2:

Code
public partial class Form2 : Form
{
   public Form1 Form { get; }
   public Form2(Form1 f)
   {
      Form = f;
   }

   private void button1_Click(object sender, EventArgs e)
   {
      //call method that starts game in form1, example:
      Form.StartGame();
   }
}

And in your first for you can show Form2 like this:

Code
new Form2(this).Show();

Sorry if the code is aligned weird, I'm writing this on phone
Its fine guys, i have got it fixed from a help of a friend. Thanks everyone for your support.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by LeonieHackPetaBytes2Jan 23, 2019 05:10 PM 1 227 Jan 23, 2019 05:10 PM
Last Post: 0xDEAD10CC
[.NET] by DatageniNov 15, 2015 05:48 AM 2 282 Nov 15, 2015 05:48 AM
Last Post: Datageni
[C#] by SIM-810273Dec 3, 2014 04:14 PM 17 358 Dec 3, 2014 04:14 PM
Last Post: SL x TnT