//This is the Form Factory method static IView CreateForm <T>(Type typ, IService <T> service) where T : class, new() { IView form = null; IPresenter pres = null; string versionNumber = ConfigurationManager.AppSettings[APP_VERSION_CONFIG].ToString(); string prefix = $"Lexicon Manager 2019 {versionNumber} - "; string suffix = string.Empty; if (typ == typeof(WordListGrid)) { suffix = "Word List Grid"; pres = new WordListPresenter <LexiconRaw, ILexiconService <LexiconRaw> >(service as ILexiconService <LexiconRaw>); form = new WordListGrid(pres); form.Name = LEXICON_ENTRY_SCREEN; form.PreviousFormName = string.Empty; form.NextFormName = WORD_LIST_SCREEN; ((IViewWordListGrid)(form)).AddingRecord += Program_AddingRecord; //Set "false" for the Previous screen, bc this is the first screen (there's no previous screen to move to. //Since this is read-only screen, it should always have permission to move forward. form.ConfirmNavigateToPreviousScreen = ConfirmNavigation.StayOnCurrentScreen; form.ConfirmNavigateToNextScreen = ConfirmNavigation.MoveToNextScreen; } else if (typ == typeof(LexiconEntryScreen)) { suffix = "Data Entry Screen"; pres = new LexiconEntryPresenter <LexiconRaw, ILexiconService <LexiconRaw> >(service as ILexiconService <LexiconRaw>); form = new LexiconEntryScreen(pres); form.Name = WORD_LIST_SCREEN; form.PreviousFormName = LEXICON_ENTRY_SCREEN; form.NextFormName = LEXICON_ENTRY_SCREEN; //This is also a read-only screen. Since it's the middle screen, it should always have unconditional permission to move forward and backwards. form.ConfirmNavigateToPreviousScreen = ConfirmNavigation.MoveToNextScreen; form.ConfirmNavigateToNextScreen = ConfirmNavigation.MoveToNextScreen; } if (pres != null && form != null) { //Can't do the following - access is private: //((Form)(form)).CenterToScreen(); //...and this executes too late, so you have to also do this inside the Form: //this.WindowState = FormWindowState.Maximized; form.MaximizeBox = false; form.MinimizeBox = true; pres.Setup(form); form.Text = prefix + suffix; form.PageMoveCompleted += Mamag; form.NextScreen += Form_NextScreen; form.PreviousScreen += Form_PreviousScreen; form.FormClosing += Program_FormClosing; form.CloseAll += Form_CloseAll; } return(form); }
public LexiconEntryScreen(IPresenter presenter) { InitializeComponent(); _presenter = presenter as LexiconEntryPresenter <LexiconRaw, ILexiconService <LexiconRaw> >; }