本文整理汇总了C#中System.Windows.Controls.Control.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Focus方法的具体用法?C# Control.Focus怎么用?C# Control.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Control
的用法示例。
在下文中一共展示了Control.Focus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Focus
public static void Focus(Control control)
{
if (control == null)
{
return;
}
var window = Window.GetWindow(control);
if (window == null)
{
return;
}
//can't invoke Focus when window is inactive
//since this causes issues with Window.Activated event and Window.IsActive value
if (window.IsActive)
{
_controlToFocus = null;
control.Focus();
}
else
{
window.Activated -= Window_Activated;
window.Activated += Window_Activated;
_controlToFocus = control;
}
}
示例2: TrySetText
private static void TrySetText(Control element, string text)
{
var peer = FrameworkElementAutomationPeer.FromElement(element);
var provider = peer == null ? null : peer.GetPattern(PatternInterface.Value) as IValueProvider;
if (provider != null)
{
provider.SetValue(text);
}
else if (element is TextBox)
{
var textBox = element as TextBox;
textBox.Text = text;
textBox.SelectionStart = text.Length;
}
else if (element is PasswordBox)
{
var passwordBox = element as PasswordBox;
passwordBox.Password = text;
}
else
{
throw new AutomationException("Element does not support SendKeys.", ResponseStatus.UnknownError);
}
// TODO: new parameter - FocusState
element.Focus();
}
示例3: OKCancelControlContainer
public OKCancelControlContainer(Control control, string caption)
: this()
{
Name = control.Name;
if (string.IsNullOrEmpty(Name))
{
var type = control.GetType();
//если контрол собственный, а Name не задан - то подставл¤ем им¤ типа
Name = type.Namespace.StartsWith("System.")?null:type.Name;
}
if (string.IsNullOrEmpty(Name))
throw new ArgumentException(Properties.Resources.ControlNameCanNotBeEmpty);
Title = caption;
double initialViewWidth = control.Width;
double initialViewHeight = control.Height;
Width = initialViewWidth + 22;
Height = initialViewHeight + 77;
if (control.MinWidth != 0)
MinWidth = control.MinWidth + 22;
if (control.MinHeight != 0)
MinHeight = control.MinHeight + 77;
// if (control.MaxWidth != 0)
// MaxWidth = control.MaxWidth + 22;
//
// if (control.MaxHeight != 0)
// MaxHeight = control.MaxHeight + 77;
control.Width = Double.NaN;
control.Height = Double.NaN;
Control = control;
//если контрол может сам посылать сообщение о закрытии - то подключаем соответствующий обработчик
if (control is IClosable)
((IClosable)control).CloseFired += ClosableControl_CloseFired;
control.Focus();
}
示例4: CheckDefaultMethods
static public void CheckDefaultMethods (Control c)
{
Assert.IsFalse (c.ApplyTemplate (), "ApplyTemplate");
Assert.IsFalse (c.Focus (), "Focus");
}
示例5: PromptUserForInput
private void PromptUserForInput(string message, Control control)
{
if (_messageBoxIsShown)
return;
_messageBoxIsShown = true;
MessageBox.Show(message);
_messageBoxIsShown = false;
control.Focus();
}
示例6: ShowRequiredWarning
/// <summary>
/// Method used to show warnings of required text fields.
/// </summary>
/// <param name="control">The text field</param>
/// <param name="message">Warning message</param>
private void ShowRequiredWarning(Control control, string message)
{
MessageBox.Show(message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
control.Focus(); //Focus on the required control.
}
示例7: ResetToPt
/// <summary>
/// 恢复导航到控件的初始值
/// </summary>
/// <param name="ToControl"></param>
private void ResetToPt(Control ToControl, double left, double opc)
{
ToControl.Opacity = opc;
ToControl.Margin = new Thickness(left, 0, 0, 0);
ToControl.RenderTransform = new CompositeTransform();
ToControl.RenderTransformOrigin = new Point(0.5, 0.5);
ToControl.Visibility = System.Windows.Visibility.Visible;
ToControl.Focus();
}
示例8: ValidateControl
bool ValidateControl(Control control, string messageString)
{
if (control is TextEdit)
{
if (string.IsNullOrEmpty((control as TextEdit).Text))
{
MessageBox.Show("请填写" + messageString);
control.Focus();
return false;
}
return true;
}
if (control is ComboBoxEdit)
{
if ((control as ComboBoxEdit).SelectedIndex == -1)
{
MessageBox.Show("请填写" + messageString);
control.Focus();
return false;
}
return true;
}
if (control is ComboBox)
{
if ((control as ComboBox).SelectedIndex == -1)
{
MessageBox.Show("请填写" + messageString);
control.Focus();
return false;
}
return true;
}
//MessageBox.Show("请填写" + messageString);
return true;
}
示例9: SetFocusAfterDelay
private void SetFocusAfterDelay(Control ctl)
{
// This is horrible but is needed to get around some WPF weirdness with setting the focus
Thread.Sleep(100);
Dispatcher.BeginInvoke((ThreadStart)delegate()
{
ctl.Focus();
FocusManager.SetFocusedElement(ctl, ctl);
Keyboard.Focus(ctl);
});
}
示例10: setActiveControl
public void setActiveControl(Control c)
{
activecontrol = c;
c.Focus();
}
示例11: move
private void move(List<Control> c, int move)
{
cursorindex = c.IndexOf(activecontrol) + move;
checkIndex(c);
activecontrol = c[cursorindex];
activecontrol.Focus();
}
示例12: MarkErrorField
private static void MarkErrorField(Control control, Label label = null)
{
control.Background = new SolidColorBrush(Colors.MistyRose);
if (label != null)
label.Foreground = new SolidColorBrush(Colors.Red);
control.Focus();
Keyboard.Focus(control);
}
示例13: ValidationContext
/* private void btnSave_Click(object sender, RoutedEventArgs e)
{
if (!IsInvalid())
{
if (txtTarget.Text.Trim() == "" || Convert.ToDouble(txtTarget.Text) <= 0)
{
MessageBox.Show("For target enter a number greater than 0.");
return;
}
_vm.Save();
}
dgTargets.ItemsSource = _vm.OutletTargets;
}*/
/* bool IsInvalid()
{
var validationContext = new ValidationContext(LayoutRoot.DataContext, null, null);
List<ValidationResult> validationResults = new List<ValidationResult>();
var isInvalid = false;
var selectedRoute = cmbRoutes.SelectedText as MasterEntity;
if (selectedRoute.Id == Guid.Empty)
{
ValidationResult vr = new ValidationResult(true, _messageResolver.GetText("sl.target.validation.selectroute")/*"Select route"#1#);
HighlightControl(cmbRoutes, vr);
isInvalid = true;
}
var selectedOutlet = cmbOutlets.SelectedValue as MasterEntity;
if (selectedOutlet == null || selectedOutlet.Id == Guid.Empty)
{
ValidationResult vr = new ValidationResult(true, _messageResolver.GetText("sl.target.validation.selectoutelt")/*"Select outlet"#1#);
HighlightControl(cmbOutlets, vr);
isInvalid = true;
}
var selectedPeriod = cmbPeriod.SelectedValue as MasterEntity;
if (selectedPeriod.Id == Guid.Empty)
{
ValidationResult vr = new ValidationResult(true, _messageResolver.GetText("sl.target.validation.selecttargetperiod")/*"Select target period"#1#);
HighlightControl(cmbPeriod, vr);
isInvalid = true;
}
//if (Convert.ToDouble(txtTarget.Text) <= 0)
//{
// ValidationResult vr = new ValidationResult("Enter target value greater than 0");
// HighlightControl(cmbPeriod, vr);
// isInvalid = true;
//}
if (!Validator.TryValidateObject(LayoutRoot.DataContext, validationContext, validationResults as ICollection<System.ComponentModel.DataAnnotations.ValidationResult>))
{
//foreach (var error in validationResults)
// HighlightControl(dictValidationControls[error.MemberNames.First()], error);
isInvalid = true;
}
return isInvalid;
}*/
#region Validation
void HighlightControl(Control control, ValidationResult result)
{
//ToolTip tooltip = GetTooltip(control);
//tooltip.DataContext = result.ErrorMessage;
//tooltip.Template = this.Resources["ValidationToolTipTemplate"] as ControlTemplate;
if (!control.Focus())
VisualStateManager.GoToState(control, "InvalidUnfocused", true);
else
VisualStateManager.GoToState(control, "InvalidFocused", true);
}
示例14: ResultMessageBox
public override void ResultMessageBox(MessageBoxResult _MessageBoxResult, Control _errCtl)
{
if (_MessageBoxResult == MessageBoxResult.OK)
{
#region 更新処理
UpdateData();
#endregion
}
else
{
switch (_errCtl.Name)
{
case "dg":
_errCtl.Focus();
this.dg.SelectedIndex = _selectIndex;
dg.CurrentColumn = dg.Columns[_selectColumn];
ExBackgroundWorker.DoWork_Focus(_errCtl, 10);
break;
default:
ExBackgroundWorker.DoWork_Focus(_errCtl, 10);
break;
}
}
}
示例15: ResultMessageBox
public override void ResultMessageBox(MessageBoxResult _MessageBoxResult, Control _errCtl)
{
if (_MessageBoxResult == MessageBoxResult.OK)
{
#region 更新処理
switch (this.utlFunctionKey.gFunctionKeyEnable)
{
case Utl_FunctionKey.geFunctionKeyEnable.New:
case Utl_FunctionKey.geFunctionKeyEnable.Init:
UpdateData(Common.geUpdateType.Insert);
break;
case Utl_FunctionKey.geFunctionKeyEnable.Upd:
UpdateData(Common.geUpdateType.Update);
break;
default:
break;
}
#endregion
}
else
{
if (_errCtl != null)
{
switch (_errCtl.Name)
{
case "dg":
_errCtl.Focus();
this.dg.SelectedIndex = _selectIndex;
dg.CurrentColumn = dg.Columns[_selectColumn];
break;
default:
ExBackgroundWorker.DoWork_Focus(_errCtl, 10);
break;
}
}
}
}