protected override void OnLeave(BlockableEventArgs e) { double d; if (double.TryParse(Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out d)) { currentvalue = d; } else { Text = entrytext; e.Block = true; } base.OnLeave(e); }
protected void Init(Control ctrl, GUIObject guiobj) { Control = ctrl; ctrl.Tag = guiobj; //so that we can map control to GUIObject backwards if (!(this is WinFormsWindow)) //windows has own handling of enter/leave { Control.Validating += (s, e) => { BlockableEventArgs be = new BlockableEventArgs(); Widget.TriggerLeave(be); e.Cancel = be.Block; }; Control.Enter += (s, e) => { Widget.TriggerEnter(new EventArgs()); }; } }
void Form_FormClosing(object sender, FormClosingEventArgs e) { Window window = ((Window)Control.Tag); BlockableEventArgs edata = new BlockableEventArgs(); ((Window)Control.Tag).TriggerClosing(edata); if (edata.Block) { e.Cancel = true; return; } //use default behaviour for modal winforms if (Form.Modal) { return; } //do not block mainwindow from closing if we for some stupid reason has set AutoDispose to false for it if (window == Guppy.MainWindow) { return; } //avoid normal close which will dispose forms which are not shown modally if (AutoDispose) { e.Cancel = false; } else { //check if the mainform is still open if (e.CloseReason == CloseReason.ApplicationExitCall || e.CloseReason == CloseReason.WindowsShutDown) { return; //allow close on application exit } e.Cancel = true; Form.Hide(); } }