public void ShowTextBox(Rectangle screenLocation, string initialText, IPropertyEntry sender, Point screenClickPos) { if (EntryWithTextBox != null) { EntryWithTextBox.EndEdit(true, textBox.Modified, textBox.Text); } EntryWithTextBox = sender; textBox.Text = initialText; textBox.Modified = false; textBox.Visible = true; textBox.Bounds = RectangleToClient(screenLocation); textBox.BringToFront(); int lastInd = Math.Max(initialText.Length - 1, 0); Point lastCharPos = textBox.GetPositionFromCharIndex(initialText.Length - 1); int charWidth = textBox.Font.Height * 5 / 7; // some guess if (initialText.Length > 0) { charWidth = lastCharPos.X / initialText.Length; } Point clickPos = textBox.PointToClient(screenClickPos); int charindex = textBox.GetCharIndexFromPosition(new Point(clickPos.X + charWidth / 2, clickPos.Y)); if (clickPos.X > lastCharPos.X + charWidth) { // clicked behind the last character: select all textBox.SelectAll(); } else { // clicked somewhere inside the text textBox.Select(charindex, 0); } textBox.Show(); textBox.Focus(); }
public void UnSelected(IPropertyEntry unselected) { // the entry with the textBox or listBox is being unselected (by as mouseClick on a different entry), so we accept the input as valid (not aborted) if (EntryWithTextBox == unselected) { EntryWithTextBox.EndEdit(false, textBox.Modified, textBox.Text); HideTextBox(); } else if (EntryWithListBox == unselected) { EntryWithListBox.ListBoxSelected(listBox.SelectedIndex); HideListBox(); } }
private void TabControl_SelectedIndexChanged(object sender, EventArgs e) { if (ActivePropertyPage != null) //Can be null if the selected tab is not a PropertyPage. { if (EntryWithTextBox != null && !ActivePropertyPage.ContainsEntry(EntryWithTextBox)) { EntryWithTextBox.EndEdit(true, textBox.Modified, textBox.Text); HideTextBox(); } if (EntryWithListBox != null && !ActivePropertyPage.ContainsEntry(EntryWithTextBox)) { HideListBox(); } ActivePropertyPage.SelectEntry(ActivePropertyPage.GetCurrentSelection()); // this shows the text-box or list-box } }
private void TextBox_KeyUp(object sender, KeyEventArgs e) { if (EntryWithTextBox != null && e.KeyCode != Keys.Tab && textBox.Modified) { // EditTextChanged fixes the input of a ConstructAction, i.e. the mouse-move is not forwarded to this input any more // so if you start entering text into a text-box you don't want the mouse-movement to alter this text. // Now using the member variable textBoxIsUpdatingFromKeystroke, which is true, when a change happens because of a keystroke // in the text-box. textBoxIsUpdatingFromKeystroke = true; try { bool ok = EntryWithTextBox.EditTextChanged(textBox.Text); textBox.Modified = false; // so on EndEdit we do not update the same value twice // curly red underlines when OK is false? } finally { textBoxIsUpdatingFromKeystroke = false; } } }
public void PreProcessKeyDown(Substitutes.KeyEventArgs e) { // this is being called after the ActiveAction has preprocessed (and not handled) the key down message // we can handle it here, before it gets handled by maybe and edit text box or something else (menu?) switch ((Substitutes.Keys)((int)e.KeyData & 0x0FFFF)) // was KeyCode, but didn't work { case Substitutes.Keys.Tab: if ((e.KeyData & Substitutes.Keys.Control) != 0) { // we use the Ctrl key to switch between property pages int sel = -1; for (int i = 0; i < tabControl.TabPages.Count; i++) { if (tabControl.TabPages[i] == tabControl.SelectedTab) { sel = i; break; } } if (sel >= 0) { if ((e.KeyData & Substitutes.Keys.Shift) != 0) { sel = (sel + tabControl.TabPages.Count - 1) % tabControl.TabPages.Count; } else { sel = (sel + 1) % tabControl.TabPages.Count; } tabControl.SelectedTab = tabControl.TabPages[sel]; } } else { if (EntryWithTextBox != null) { EntryWithTextBox.EndEdit(false, textBox.Modified, textBox.Text); HideTextBox(); } else if (EntryWithListBox != null) { EntryWithListBox.ListBoxSelected(listBox.SelectedIndex); HideListBox(); } SelectNextEntry((e.KeyData & Substitutes.Keys.Shift) == 0); } e.Handled = true; e.SuppressKeyPress = true; break; case Substitutes.Keys.Enter: if (EntryWithTextBox != null) { EntryWithTextBox.EndEdit(false, textBox.Modified, textBox.Text); HideTextBox(); } else if (EntryWithListBox != null) { EntryWithListBox.ListBoxSelected(listBox.SelectedIndex); HideListBox(); } else if (ActivePropertyPage is PropertyPage pp) { pp.OnEnter(); } e.Handled = true; break; case Substitutes.Keys.Escape: if (EntryWithTextBox != null) { EntryWithTextBox.EndEdit(true, textBox.Modified, textBox.Text); HideTextBox(); e.Handled = true; } else if (EntryWithListBox != null) { // no notification of the entry, nothing has changed until now HideListBox(); e.Handled = true; } break; case Substitutes.Keys.Down: SelectNextEntry(true); e.Handled = true; break; case Substitutes.Keys.Up: SelectNextEntry(false); e.Handled = true; break; } }