I'm writing an application where the main form has to be hidden, but it shows a dialogue when it starts up.
My main form has the following line in an initialize() method that is called by the constructor.
this.Load += new System.EventHandler(this.MainForm_Load);
I've verified that the code above it hit But the MainForm_Load() method is never called.
Could this be because I am hiding the form?
I execute the following line in the Main of Program.cs:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
And have overridden the following method in the Form:
protected override void SetVisibleCore(bool value)
{
_logger.Debug("Hiding the main window");
base.SetVisibleCore(allowShowDisplay ? value : allowShowDisplay);
}
Where allowShowDisplay is set to false;
I found at least part of this solution in the answer to this queston and have used it in another project. That project didn't use the form load event though. The one I'm working on does.
UPDATE This is what the Main method looks like. I'm trying to inject the dependancies into the all the elements. I've changed the names to remove customer names.
[STAThread] static void Main() {
ServiceHost incomingPipeHost = new ServiceHost(typeof(ScreenPopService));
incomingPipeHost.Open();
XmlConfigurator.Configure();
_logger.Debug("Starting Application");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
_logger.Debug("Creating subformView");
ISubformView subformView = new SubformView();
_logger.Debug("Creating MainForm mainForm");
MainForm mainForm = new MainForm();
_logger.Debug("Creating MonitorController");
IMonitorController MonitorController = new MonitorController();
_logger.Debug("Adding View to MonitorController");
MonitorController.View = mainForm;
_logger.Debug("Adding subFormView to mainForm");
mainForm.SubFormView = subFormView;
_logger.Debug("Adding MonitorController to mainForm");
mainForm.MonitorController = MonitorController;
_logger.Debug("Loading Properties");
IProperties properties = PropertiesManager.LoadProperties();
_logger.DebugFormat("Loaded Properties [{0}]", properties);
_logger.Debug("Setting properties on mainForm");
mainForm.Properties = properties;
_logger.Debug("Setting properties on MonitorController");
MonitorController.Properties = properties;
_logger.Debug("Settting ScreenPop Consumer on MonitorCotroller");
MonitorController.screenPopConsumer = ScreenPopCallBackManager.Instance;
_logger.Debug("Debug Running Application");
Application.Run(mainForm);
}