I need your help with c# and some graphic issues: I'm developing a very simple application. There is a unique form called DeltaPregView, a controller for the form called DeltaPregController and a class that contains the Main of the project:
Main Class:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
namespace deltaPreg
{
static class Program
{
[MTAThread]
static void Main()
{
//create the view
DeltaPregView view = new DeltaPregView();
//link the view to the APP
Application.Run(view);
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
}
}
}
View for the class:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace deltaPreg
{
public partial class DeltaPregView : Form
{
public DeltaPregView()
{
InitializeComponent();
}
public void init()
{
prova.Visible = false;
}
}
}
and the Controller for the view:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace deltaPreg
{
class DeltaPregController
{
#region variables
private DeltaPregView view;
#endregion
public DeltaPregController(DeltaPregView view)
{
this.view = view;
//start the reading process
start();
}
private void start()
{
view.init();
}
}
}
I would like to hide the button called "prova", but nothing changes in my program. I'm a newbie in the winforms management, thank you in advance.
The problem is that you print the form before you call the init
function in DeltaPregView
.
One way to solve this is by replacing those lines:
//link the view to the APP
Application.Run(view);
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
To:
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
//link the view to the APP
Application.Run(view);