public void addFile(String filename) { //either a full-path or a relative path. FileTabPage tabPage = new FileTabPage(makeFullPath(filename), this); tabPage.SuspendLayout(); container.Controls.AddRange(new System.Windows.Forms.Control[] { tabPage }); tabPage.Location = new System.Drawing.Point(0, 0); tabPage.Text = "Untitled"; tabPage.Size = container.Size; tabPage.TabIndex = 0; tabPages.Add(tabPage); tabPage.ResumeLayout(false); tabPage.fullpath = makeFullPath(filename); tabPage.Init(); if (config != null) { config.ApplyConfiguration(tabPage.scintillaControl, "javascript"); } container.SelectedTab = tabPage; if (SelectedFileTab != null) { SelectedFileTab.Focus(); } else { container.Focus(); } }
private void FormSettings_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // Hack to handle the close/ok button in the top right corner of the window. if (DialogResult == DialogResult.None) { DialogResult = DialogResult.OK; } // Validate the form contents if OK was pressed. if (DialogResult == DialogResult.OK) { // Backup the old values so that they can be restored in the event of a validation error. object[] oldValues = new object[settings.Count]; for (int i = 0; i < settings.Count; i++) { oldValues[i] = settings[i].Value; } // Copy the settings from the controls to the Settings object. Basic type validation // is performed here. for (int i = 0; !e.Cancel && (i < settings.Count); i++) { Setting setting = settings[i]; switch (setting.Type) { case "boolean": setting.Value = ((CheckBox)controls[i]).Checked; break; case "openfile": case "savefile": case "exefile": case "string": setting.Value = controls[i].Text; break; case "integer": try { setting.Value = int.Parse(controls[i].Text); } catch { MessageBox.Show("Invalid numerical value for " + setting.Caption, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); e.Cancel = true; } break; case "long": try { setting.Value = long.Parse(controls[i].Text); } catch { MessageBox.Show("Invalid numerical value for " + setting.Caption, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); e.Cancel = true; } break; case "double": try { setting.Value = double.Parse(controls[i].Text); } catch { MessageBox.Show("Invalid floating point value for " + setting.Caption, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); e.Cancel = true; } break; case "updown": // If the control is blank, the minimum value will be returned here. setting.Value = (int)((NumericUpDown)controls[i]).Value; break; case "comportin": case "comportout": { // Copy the setting value from the button properties, as the text box only // displays a user-friendly description of the port. setting.Value = settingButtonProperties[i].data; break; } case "combobox": { setting.Value = ((ComboBox)controls[i]).SelectedItem; break; } default: throw new Exception("Unknown setting type: " + setting.Type); } } // If no errors occurred above, use the supplied validator function. if (!e.Cancel) { string errorMessage = ""; if ((validator != null) && !validator(settings, ref errorMessage)) { MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); e.Cancel = true; } } // If a validation error occurred, restore the old settings values. if (e.Cancel) { for (int i = 0; i < settings.Count; i++) { settings[i].Value = oldValues[i]; } } } // Move the focus to something other than a text box to ensure that the text box // LostFocus is not called after the input panel has been destroyed. tabControl.Focus(); }
public void GotFocusSelectedIndex () { TabControl tc = new TabControl (); tc.TabPages.Add ("A"); tc.TabPages.Add ("B"); Button b = new Button (); // Dummy button to receive focus by default Form f = new Form (); f.Controls.AddRange (new Control [] { b, tc }); f.Show (); tc.SelectedIndex = -1; // Make sure focus goes back to button b.Focus (); // Finally give focus back to TabControl tc.Focus (); Assert.AreEqual (-1, tc.SelectedIndex, "#A0"); }