Today I tried to create a reusable Framework, and I had no problem to do this... I created a new file "Game.cs" containing the class Game:
class Game
{
Form Form;
public Game(Form Form, int Width, int Height)
{
//Set Form
this.Form = Form;
this.Form.MaximizeBox = false;
this.Form.FormBorderStyle = FormBorderStyle.Fixed3D;
this.Form.Size = new Size(Width, Height);
}
}
Then I add this file into a new Form project, Framework_Demo, using VisualStudio and it contains this:
namespace Framework_Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Here I created a new Object game using class Game
Game game = new Game(this, 600, 600);
}
}
}
Maybe this is simple and my question could be obsolete, but why when I debug Framework_Demo appears his Form but also with the properties I set in the costructor of Game class? It's not a problem but I want to know what happens when I set: this.Form = Form. It's really working like a pointer? Can someone explain this behaviour to me? Thank You!
class Game
{
Form Form;
}
Here the Form field is just a reference to another form, where you get that reference in the constructor of Game class. This is generally done to keep a reference to the owner form inside a child form. When you set Form properties in the constructor, you're actually modifying the owner form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With