当前位置: 首页>>代码示例>>C#>>正文


C# Control.Focus方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:Alexey1,项目名称:JoinToPlayClient,代码行数:25,代码来源:FocusHelper.cs

示例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();
        }
开发者ID:sleekweasel,项目名称:winphonedriver,代码行数:28,代码来源:ValueCommand.cs

示例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();
        }
开发者ID:vansickle,项目名称:dbexplorer,代码行数:45,代码来源:OKCancelControlContainer.xaml.cs

示例4: CheckDefaultMethods

		static public void CheckDefaultMethods (Control c)
		{
			Assert.IsFalse (c.ApplyTemplate (), "ApplyTemplate");
			Assert.IsFalse (c.Focus (), "Focus");
		}
开发者ID:dfr0,项目名称:moon,代码行数:5,代码来源:ControlTest.cs

示例5: PromptUserForInput

 private void PromptUserForInput(string message, Control control)
 {
     if (_messageBoxIsShown)
         return;
     _messageBoxIsShown = true;
     MessageBox.Show(message);
     _messageBoxIsShown = false;
     control.Focus();
 }
开发者ID:timextreasures,项目名称:WordPress-WindowsPhone,代码行数:9,代码来源:AddExistingWordPressBlogPage.xaml.cs

示例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.
 }
开发者ID:mariangr,项目名称:BankCardTokenization,代码行数:10,代码来源:LoginUserControl.xaml.cs

示例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();
 }
开发者ID:Red-Banana,项目名称:TabourMaster,代码行数:13,代码来源:MainPage.xaml.cs

示例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;
 }
开发者ID:elths,项目名称:GXVisa,代码行数:35,代码来源:BlackList.xaml.cs

示例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);

            });
        }
开发者ID:Pertex,项目名称:Quest,代码行数:14,代码来源:ScriptEditorControl.xaml.cs

示例10: setActiveControl

 public void setActiveControl(Control c)
 {
     activecontrol = c;
     c.Focus();
 }
开发者ID:EisakuHiguchi,项目名称:BroadCursor,代码行数:5,代码来源:BroadCursor2.cs

示例11: move

 private void move(List<Control> c, int move)
 {
     cursorindex = c.IndexOf(activecontrol) + move;
     checkIndex(c);
     activecontrol = c[cursorindex];
     activecontrol.Focus();
 }
开发者ID:EisakuHiguchi,项目名称:BroadCursor,代码行数:7,代码来源:BroadCursor2.cs

示例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);
 }
开发者ID:gwupe,项目名称:Gwupe,代码行数:8,代码来源:InputValidator.cs

示例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);
        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:75,代码来源:EditOutletTargets.xaml.cs

示例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;
                }
            }
        }
开发者ID:salesInnovation,项目名称:SalesInnovation,代码行数:26,代码来源:Utl_MstCondition.xaml.cs

示例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;
                    }
                }
            }
        }
开发者ID:salesInnovation,项目名称:SalesInnovation,代码行数:39,代码来源:Utl_InpEstimate.xaml.cs


注:本文中的System.Windows.Controls.Control.Focus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。