本文整理汇总了C#中System.Windows.Controls.TextBox.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.Focus方法的具体用法?C# TextBox.Focus怎么用?C# TextBox.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBox
的用法示例。
在下文中一共展示了TextBox.Focus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignShortcut
private void AssignShortcut(TextBox textbox, int row, int column)
{
var hotKey = new KeyBinding(new RelayCommand(() => textbox.Focus()), new MultiKeyGesture(new List<Key> { (Key)(row + 34), (Key)(column + 34) }, ModifierKeys.Control | ModifierKeys.Shift));
this.InputBindings.Add(hotKey);
if (row < 10 && column < 10)
{
hotKey = new KeyBinding(new RelayCommand(() => textbox.Focus()), new MultiKeyGesture(new List<Key> { (Key)(row + 34), (Key)(column + 34) }, ModifierKeys.Control));
this.InputBindings.Add(hotKey);
// following is not working
//hotKey = new KeyBinding(new RelayCommand(() => textbox.Focus()), new MultiKeyGesture(new List<Key> { (Key)(row + 34), (Key)(column + 34) }, ModifierKeys.Alt));
//this.InputBindings.Add(hotKey);
}
}
示例2: PrintBanner
public PrintBanner()
{
Title = "Print Banner";
SizeToContent = SizeToContent.WidthAndHeight;
// Make StackPanel content of window.
StackPanel stack = new StackPanel();
Content = stack;
// Create TextBox.
txtbox = new TextBox();
txtbox.Width = 250;
txtbox.Margin = new Thickness(12);
stack.Children.Add(txtbox);
// Create Button.
Button btn = new Button();
btn.Content = "_Print...";
btn.Margin = new Thickness(12);
btn.Click += PrintOnClick;
btn.HorizontalAlignment = HorizontalAlignment.Center;
stack.Children.Add(btn);
txtbox.Focus();
}
示例3: Use_Zip_Code
private void Use_Zip_Code(object sender, System.Windows.RoutedEventArgs e)
{
TextBox textBox = new TextBox();
// restrict input to digits:
InputScope inputScope = new InputScope();
InputScopeName inputScopeName = new InputScopeName();
inputScopeName.NameValue = InputScopeNameValue.Digits;
inputScope.Names.Add(inputScopeName);
textBox.InputScope = inputScope;
CustomMessageBox messageBox = new CustomMessageBox()
{
Message = "Enter your US zip code:",
LeftButtonContent = "okay",
RightButtonContent = "cancel",
Content = textBox
};
messageBox.Loaded += (a, b) =>
{
textBox.Focus();
};
messageBox.Show();
messageBox.Dismissed += (s, args) =>
{
if (args.Result == CustomMessageBoxResult.LeftButton)
{
if (textBox.Text.Length >= 5)
{
geocodeUsingString(textBox.Text);
}
}
};
}
示例4: WorkWithEmailBox
public static ComboBox WorkWithEmailBox(Grid grid, TextBox emailTextBox, TextCompositionEventArgs e, int columnSpanEmailBox)
{
ComboBox comboBox = new ComboBox();
const string val = "@";
if (e.Text != val) return comboBox;
if (emailTextBox.Text.Length < 1) return null;
if (emailTextBox.Text.IndexOf(val, StringComparison.Ordinal) != -1) return comboBox;
Grid.SetColumnSpan(emailTextBox, columnSpanEmailBox);
comboBox.DropDownClosed += (a, r) =>
{
if (comboBox.SelectedIndex == -1) return;
grid.Children.Remove(comboBox);
Grid.SetColumnSpan(emailTextBox, columnSpanEmailBox+2);
if (comboBox.SelectedIndex == 0)
{
emailTextBox.Text += val;
emailTextBox.Focus();
}
else
{
emailTextBox.Text += comboBox.SelectedItem.ToString();
}
emailTextBox.SelectionStart = emailTextBox.Text.Length;
emailTextBox.Focus();
};
Grid.SetRow(comboBox, 2);
comboBox.Items.Add("написать другой");
comboBox.Items.Add(val + "gmail.com");
comboBox.Items.Add(val + "mail.ru");
comboBox.Items.Add(val + "yandex.ua");
comboBox.Items.Add(val + "rambler.ru");
comboBox.Items.Add(val + "hotmail.com");
comboBox.Items.Add(val + "yahoo.com");
comboBox.Items.Add(val + "inbox.ru");
comboBox.Items.Add(val + "list.ru");
comboBox.Items.Add(val + "bk.ru");
comboBox.Items.Add(val + "mail.ua");
comboBox.Height = emailTextBox.ActualHeight;
Grid.SetColumn(comboBox, 4);
Grid.SetColumnSpan(comboBox, 2);
grid.Children.Add(comboBox);
comboBox.IsDropDownOpen = true;
comboBox.Focus();
return comboBox;
}
示例5: Limpiar
public static void Limpiar(TextBox t1, TextBox t2 = null, TextBox t3 = null)
{
t1.Clear();
if (t2 != null)
t2.Clear();
if (t3 != null)
t3.Clear();
t1.Focus();
}
示例6: OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_tbName = (TextBox) GetTemplateChild("tbName");
if (_tbName != null)
{
_tbName.Focus();
}
_pswb = (PasswordBox) GetTemplateChild("pswb");
}
示例7: OnApplyTemplate
public override void OnApplyTemplate()
{
if (textBox != null)
textBox.KeyDown -= textBox_KeyDown;
base.OnApplyTemplate();
textBox = GetTemplateChild("TextBox") as TextBox;
if (textBox != null)
textBox.Focus();
textBox.KeyDown += textBox_KeyDown;
}
示例8: CheckTextBox
public bool CheckTextBox(TextBox box)
{
if(box.Text.Length == 0)
{
MessageBox.Show("Вы ввели не все данные.");
box.Focus();
return false;
}
return true;
}
示例9: OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_tb = (TextBox) GetTemplateChild("tbName");
if (_tb != null)
{
_tb.Focus();
}
_tbError = (TextBlock) GetTemplateChild("tbError");
}
示例10: Ask
public object Ask(Parameter par)
{
var vlc = main.Children.FindByName(ValueControl);
if (vlc != null)
main.Children.Remove(vlc);
Question.Text = "";
foreach (string s in par.Question.Split(new[] { "\\n" }, StringSplitOptions.None))
{
Question.Inlines.Add(new Run { Text = s });
Question.Inlines.Add(new LineBreak());
}
if (par.ParamType == ParamType.PBool)
{
var value = new ComboBox { Width = 100, Height = 20, Name = ValueControl, Margin = new Thickness(5, 0, 0, 0) };
Grid.SetRow(value, 1);
main.Children.Add(value);
value.Items.Add(Boolean.TrueString);
value.Items.Add(Boolean.FalseString);
value.SelectedIndex = 0;
value.Focus();
}
else
{
var value = new TextBox { Width = 400, Name = ValueControl, Margin = new Thickness(5, 0, 0, 0) };
Grid.SetRow(value, 1);
main.Children.Add(value);
if (par.ParamType == ParamType.PDouble || par.ParamType == ParamType.PFuzzy)
{
value.Text = "0";
value.TextChanged += ValueTextChanged;
value.Tag = par.ParamType;
}
else
value.Tag = ParamType.PString;
value.SelectAll();
value.Focus();
}
if (ShowDialog() == true)
{
UIElement uie = main.Children.FindByName(ValueControl);
if (uie is TextBox)
{
ParamType pt = (ParamType) (uie as TextBox).Tag;
if (pt == ParamType.PDouble || pt == ParamType.PFuzzy)
return double.Parse((uie as TextBox).Text);
return (uie as TextBox).Text;
}
if (uie is ComboBox)
return bool.Parse((uie as ComboBox).Text);
}
return null;
}
示例11: UriDialog
public UriDialog()
{
Title = "Enter a URI";
ShowInTaskbar = false;
SizeToContent = SizeToContent.WidthAndHeight;
WindowStyle = WindowStyle.ToolWindow;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
txtBox = new TextBox();
txtBox.Margin = new Thickness(48);
Content = txtBox;
txtBox.Focus();
}
示例12: aSircleTextbox_LostFocus
private void aSircleTextbox_LostFocus(object sender, RoutedEventArgs e)
{
int iTextboxPosition = _getTextboxPosition(((TextBox)sender).Name);
if (iTextboxPosition != 11) //Last Textbox
{
int iNextQuestionID = ((int)iTextboxPosition / 2) + 1;
VisualStateManager.GoToState(this, _sCatapillarPrefix + "Question" + iNextQuestionID.ToString() , true);
iTextboxPosition += 2; //Next Textbox
_txtActiveInput = (TextBox)this.FindName(_sCatapillarPrefix + "Sircle" + iTextboxPosition.ToString() + "Textbox");
_txtActiveInput.Focus();
}
}
示例13: list_KeyDown
public void list_KeyDown(ListBox list, KeyEventArgs e, TextBox txtbox, Popup popup)
{
i = txtbox.CaretIndex;
switch (e.Key)
{
case Key.Enter:
txtbox.Text = Regex.Replace(txtbox.Text, @"\b" + know + @"\b", UpdatedCollection[list.SelectedIndex]);
txtbox.CaretIndex = i + UpdatedCollection[list.SelectedIndex].Length;
know = string.Empty;
popup.IsOpen = false;
e.Handled = true;
txtbox.Focus();
break;
case Key.Left:
popup.IsOpen = false;
txtbox.CaretIndex = i;
e.Handled = true;
txtbox.Focus();
break;
}
}
示例14: MeetTheDockers
public MeetTheDockers()
{
Title = "Meet the Dockers";
DockPanel dock = new DockPanel();
Content = dock;
// Create menu.
Menu menu = new Menu();
MenuItem item = new MenuItem();
item.Header = "Menu";
menu.Items.Add(item);
// Dock menu at top of panel.
DockPanel.SetDock(menu, Dock.Top);
dock.Children.Add(menu);
// Create tool bar.
ToolBar tool = new ToolBar();
tool.Header = "Toolbar";
// Dock tool bar at top of panel.
DockPanel.SetDock(tool, Dock.Top);
dock.Children.Add(tool);
// Create status bar.
StatusBar status = new StatusBar();
StatusBarItem statitem = new StatusBarItem();
statitem.Content = "Status";
status.Items.Add(statitem);
// Dock status bar at bottom of panel.
DockPanel.SetDock(status, Dock.Bottom);
dock.Children.Add(status);
// Create list box.
ListBox lstbox = new ListBox();
lstbox.Items.Add("List Box Item");
// Dock list box at left of panel.
DockPanel.SetDock(lstbox, Dock.Left);
dock.Children.Add(lstbox);
// Create text box.
TextBox txtbox = new TextBox();
txtbox.AcceptsReturn = true;
// Add text box to panel & give it input focus.
dock.Children.Add(txtbox);
txtbox.Focus();
}
示例15: IsOkay
private bool IsOkay(String input, TextBox sender)
{
if (input.Length > 0)
{
return true;
}
else
{
MessageBox.Show("Check the input.");
sender.Focus();
sender.SelectAll();
return false;
}
}