private void AddText(char c) { txtWord.SelectedText = c.ToString(); txtWord.SelectionLength = 0; txtWord.SelectionStart += 1; txtWord.Focus(); }
//後ろから前に向けての検索 private void SearchBackward(object o) { System.Windows.Controls.TextBox textDetail = (System.Windows.Controls.TextBox)o; if (string.IsNullOrEmpty(textDetail.Text)) { return; } //フォーカス設定 textDetail.Focus(); //検索開始位置の設定 int searchStartIndex = (textDetail.SelectionStart + SearchText2.Length - 1) - 1; if (searchStartIndex < 0) { return; //先頭の場合は処理を抜けます } //検索開始位置が末尾以降になる場合は、検索開始位置を末尾にします if (searchStartIndex > textDetail.Text.Length) { searchStartIndex = textDetail.Text.Length; } //検索 int index = textDetail.Text.LastIndexOf(SearchText2, searchStartIndex, StringComparison.OrdinalIgnoreCase); if (index >= 0) { //見つかった場合 textDetail.Select(index, SearchText2.Length); } }
/// <summary> /// Handles key tip pressed /// </summary> public override void OnKeyTipPressed() { if (!IsTemplateValid()) return; // Use dispatcher to avoid focus moving to backup'ed element // (focused element before keytips processing) Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (ThreadStart)(() => { textBox.SelectAll(); textBox.Focus(); })); base.OnKeyTipPressed(); }
static void frameworkElement_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (((bool)e.NewValue)) { if (sender is System.Windows.Controls.TextBox) { System.Windows.Controls.TextBox textBox = sender as System.Windows.Controls.TextBox; if (textBox != null) { textBox.SelectAll(); textBox.Focus(); } } ((FrameworkElement)sender).Focus(); } }
public void ActivatingChildControlRaisesSmartPartActivatedForContainingSP() { ZoneWorkspaceForm zoneForm = new ZoneWorkspaceForm(); workItem.Items.Add(zoneForm); zoneForm.Show(); System.Windows.Controls.ContentControl sp = new System.Windows.Controls.ContentControl(); System.Windows.Controls.TextBox tb = new System.Windows.Controls.TextBox(); sp.Content = tb; zoneForm.Workspace.Show(sp); zoneForm.Workspace.Show(new Control()); System.Windows.Controls.Control received = null; zoneForm.Workspace.SmartPartActivated += delegate(object sender, WorkspaceEventArgs e) { received = (System.Windows.Controls.Control)e.SmartPart; }; tb.Focus(); Assert.AreSame(sp, received); }
/* * 検索設定はここを参照 * https://9cubed.info/article/nine_cubed_memo/20180524/ */ //前から後ろに向けての検索 private void SearchForward(object o) { System.Windows.Controls.TextBox textDetail = (System.Windows.Controls.TextBox)o; if (string.IsNullOrEmpty(textDetail.Text)) { return; } //フォーカス設定 textDetail.Focus(); //検索する //選択文字列が検索文字列と同じ場合は、次の文字列から検索します int offset = textDetail.SelectedText.Equals(SearchText2, StringComparison.OrdinalIgnoreCase) ? 1 : 0; int index = textDetail.Text.IndexOf(SearchText2, textDetail.SelectionStart + offset, StringComparison.OrdinalIgnoreCase); if (index >= 0) { //見つかった場合 textDetail.Select(index, SearchText2.Length); } }
public void FocusOnInnerControlActivatesContainingSmartPart() { ZoneWorkspaceForm form = new ZoneWorkspaceForm(); workItem.Items.Add(form); form.Show(); System.Windows.Controls.ContentControl sp1 = new System.Windows.Controls.ContentControl(); System.Windows.Controls.TextBox tb = new System.Windows.Controls.TextBox(); sp1.Content = tb; System.Windows.Controls.ContentControl sp2 = new System.Windows.Controls.ContentControl(); System.Windows.Controls.TextBox tb2 = new System.Windows.Controls.TextBox(); sp2.Content = tb2; form.Workspace.Show(sp1, new ZoneSmartPartInfo("LeftZone")); form.Workspace.Show(sp2, new ZoneSmartPartInfo("ContentZone")); Assert.AreSame(sp2, form.Workspace.ActiveSmartPart); tb.Focus(); Assert.AreSame(sp1, form.Workspace.ActiveSmartPart); tb2.Focus(); Assert.AreSame(sp2, form.Workspace.ActiveSmartPart); }
void Clear() { textBox.Focus(); textBox.Text = initialCmdMark + cmdMark; SetCursorLast(); }
public static void CheckField(object _controle, bool _proibeBranco = true, string _tooltip = "", string _tipo = "") { string _controleType = _controle.GetType().ToString(); if (_controleType == "System.Windows.Controls.TextBox") { System.Windows.Controls.TextBox _textBox = (System.Windows.Controls.TextBox)_controle; switch (_tipo) { case ("00/00/0000"): //if (!_escape) //{ if (!CheckDate(_textBox.Text, _proibeBranco)) { if (PopupBox("Data Inválida (pressione [Esc] para cancelar)", 1)) { _textBox.Focus(); } else { _textBox.Text = ""; } } //} //else //{ // _textBox.Text = ""; //} //_escape = false; break; case ("CPF"): //if (!_escape) //{ if (!ValidaCPF(_textBox.Text)) { if (PopupBox("CPF Inválido (pressione [Esc] para cancelar)", 1)) { _textBox.Focus(); } else { _textBox.Text = ""; } } //} //else //{ // _textBox.Text = ""; //} //_escape = false; break; case ("CNPJ"): if (!ValidaCNPJ(_textBox.Text)) { if (PopupBox("CNPJ Inválido (pressione [Esc] para cancelar)", 1)) { _textBox.Focus(); } else { _textBox.Text = ""; } } break; } } else if (_controleType == "System.Windows.Controls.TextBox") { System.Windows.Controls.TextBox _textBox = (System.Windows.Controls.TextBox)_controle; if (_textBox.Text.Trim() == "") { if (PopupBox("Campo [ " + _tooltip + " ] em branco é Inválido", 1)) { _textBox.Focus(); } //if (!_escape) //{ // PopupBox("Campo [ " + _tooltip + " ] em branco é Inválido", 1); // _textBox.Focus(); //} //_escape = false; } } else if (_controleType == "") { } }