1- Create a new property In Form2
like this
public partial class Form2: Form
{
public static bool BolleanProperty { get; set; }
// ...
}
2- in the static constructor set property BolleanProperty = true
public partial class Form2: Form
{
public static bool BolleanProperty { get; set; }
static Form2()
{
BolleanProperty = true;
}
public Form2()
{
InitializeComponent();
}
}
3- Now in Form1
, you can access the property in Form2
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = Form2.BolleanProperty.ToString();
}
Updated my answer for the new contributor Luuk Scherjon
To do this in your case, you can follow these steps
-
Create tow public properties in
Form3UpgradesGunSounds
.public bool TankCannon100 { get; set; } public bool TankCannon120 { get; set; }
-
In
Form3UpgradesGunSounds_MouseDoubleClick
eventreplace
_tankCannon100
&_tankCannon120
with the properties was createdif (...) // FireTankCannon100 TankCannon100 = true; else if (...) // FireTankCannon120 TankCannon120 = true;
-
Now in
Form1Game
>MoleShooter_MouseClick
you can access the properties created inForm3UpgradesGunSounds
public void MoleShooter_MouseClick(object sender, MouseEventArgs e) { // ... Form3UpgradesGunSounds fr3UpgradesSounds = new Form3UpgradesGunSounds(); if (!fr3UpgradesSounds.TankCannon100) { // do something } if (fr3UpgradesSounds.TankCannon120) { // do something } // ... }
0
solved How can I get a Boolean from form 2 to form1?