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


C# Control.Focus方法代码示例

本文整理汇总了C#中System.Windows.Forms.Control.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Focus方法的具体用法?C# Control.Focus怎么用?C# Control.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.Control的用法示例。


在下文中一共展示了Control.Focus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckControlInput

        public static bool CheckControlInput(Control ctrl, string strCaption, int iLength, bool blnNumber)
        {
            try
            {
                if (ctrl.GetType().ToString() == "System.Windows.Forms.TextBox")
                {
                    if (ctrl.Text.Trim() == "")
                    {
                        MsgBoxExclamation(strCaption + "不能为空,请输入" + strCaption);
                        ctrl.Focus();
                        ((TextBox)ctrl).SelectAll();
                        return false;
                    }
                    else if (iLength > 0 && ctrl.Text.Length != iLength)
                    {
                        MsgBoxExclamation("请输入" + iLength.ToString() + "位" + strCaption);
                        ctrl.Focus();
                        ((TextBox)ctrl).SelectAll();
                        return false;
                    }

                    if (blnNumber && !IsNumeric(ctrl.Text))
                    {
                        MsgBoxExclamation(strCaption + "必须为数字,请重新输入");
                        ctrl.Focus();
                        ((TextBox)ctrl).SelectAll();
                        return false;
                    }
                }
                else if (ctrl.GetType().ToString() == "System.Windows.Forms.ComboBox")
                {
                    if (ctrl.Text.Trim() == "")
                    {
                        MsgBoxExclamation(strCaption + "不能为空,请选择" + strCaption);
                        ctrl.Focus();
                        return false;
                    }
                }
                else
                {
                    if (ctrl.Text.Trim() == "")
                    {
                        MsgBoxExclamation(strCaption + "不能为空,请输入" + strCaption);
                        ctrl.Focus();
                        return false;
                    }
                }

                return true;
            }
            catch (System.Exception e)
            {
                MsgBoxException(e.Message, "GlobalFunction.CheckControlInput");
                return false;
            }
        }
开发者ID:ideayapai,项目名称:docviewer,代码行数:56,代码来源:GlobalFunction.cs

示例2: PopupEditorHost

        public PopupEditorHost(Control control,
            int left, int top, int width, int height,
            Func<Control, object> getControlValue, 
            Action<object> onValueUpdated)
            : this()
        {
            this.getControlValue = getControlValue;
            this.onValueUpdated = onValueUpdated;
            Content = control;

            Margin = Padding.Empty;
            Padding = Padding.Empty;
            //AutoSize = true;
            Width = width;
            Height = height;
            Left = left;
            Top = top;
            Content.Dock = DockStyle.Fill;

            BindContentHandlers();

            var host = new ToolStripControlHost(Content)
            {
                Margin = Padding.Empty,
                Padding = Padding.Empty,
                AutoSize = false,
                Width = width,
                Height = height
            };
            Items.Add(host);
            Opened += (sender, e) => Content.Focus();
        }
开发者ID:suspended,项目名称:TradeSharp,代码行数:32,代码来源:PopupEditorHost.cs

示例3: ActivateNextControl

        private void ActivateNextControl()
        {
            if ( CurrentControl == null )
            {
                CurrentControl = ControlOrder[0];
                CurrentControl.Focus();
                CurrentControl.BackColor = Color.Yellow;
                return;
            }

            var currentIndex = ControlOrder.IndexOf( CurrentControl );
            CurrentControl.BackColor = Color.Gray;

            if ( ControlOrder.Count > currentIndex + 1 )
            {
                CurrentControl = ControlOrder[currentIndex + 1];
                CurrentControl.Focus();
                CurrentControl.BackColor = Color.Yellow;
            }
            else
            {
                kbd_SaveAndReboot.Visible = true;
                kbd_SaveAndReboot.Enabled = true;
            }
        }
开发者ID:jennings,项目名称:LaunchPad,代码行数:25,代码来源:AlohaManualConfigWindow.cs

示例4: ShowError

        /// <summary>
        /// ȱʡ����ControlValueNullException��ʽ
        /// </summary>
        /// <param name="ex"></param>
        public void ShowError(object invalidControl, string msg)
        {
            if (invalidControl == null)
            {
                throw new ArgumentNullException("invalidControl");
            }

            IWindowControl windowControl = invalidControl as IWindowControl;
            if (windowControl != null)
            {
                //ClearError();

                if (m_firstInvalidControl == null)
                {
                    m_firstInvalidControl = windowControl.Control;
                    //if (ex.InvalidDataControl is Feng.Windows.Forms.DataControlWrapper)
                    //{
                    //    m_invalidControl = ex.InvalidDataControl as Control;
                    //}
                    m_firstInvalidControl.Focus();
                }

                ShowErrorIcon(windowControl.Control, msg);
            }
            else
            {
                ServiceProvider.GetService<IMessageBox>().ShowWarning(msg);
            }
        }
开发者ID:urmilaNominate,项目名称:mERP-framework,代码行数:33,代码来源:ErrorProviderControlCheckExceptionProcess.cs

示例5: btnGuardar_Click

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //Esta forma de validar, valida de a uno los errores. Como errores particulares
            //en este formulario tengo este por ahora. No lo veo mal. Habría que ver cómo se lleva
            //con los errores propios de los controles (validar campo obligatorio de user control texto y demás)
            primerControlInvalido = null;
            this.ValidateChildren();

            if (primerControlInvalido != null) primerControlInvalido.Focus();
            else
            {
                Dictionary<String, gdDataBase.ValorTipo> camposValores = new Dictionary<string, gdDataBase.ValorTipo>();
                Dictionary<int, String> errorMensaje = new Dictionary<int, string>();

                camposValores.Add("fecha_salida", new gdDataBase.ValorTipo(dateTimePickerSalida.Value.ToString("yyyy-MM-dd HH:mm:ss.000"), SqlDbType.DateTime));
                camposValores.Add("fecha_llegada_estimada", new gdDataBase.ValorTipo(dateTimePickerEstimada.Value.ToString("yyyy-MM-dd HH:mm:ss.000"), SqlDbType.DateTime));
                camposValores.Add("hoy", new gdDataBase.ValorTipo(Config.fecha.ToString(), SqlDbType.DateTime));
                camposValores.Add("matricula", new gdDataBase.ValorTipo(textBoxMatricula.Text, SqlDbType.VarChar));
                camposValores.Add("id_ruta", new gdDataBase.ValorTipo(idRuta.ToString(), SqlDbType.VarChar));

                errorMensaje.Add(60007, "La matricula ingresada no pertenece a ninguna Aeronave");
                errorMensaje.Add(600012, "La ruta ingresada no existe");
                errorMensaje.Add(600015, "El servicio brindado por la aeronave no coincide con el de la ruta");
                errorMensaje.Add(600016, "La aeronave ya posee un viaje en esas fechas");

                var ejecucion = new SPPureExec("ÑUFLO.GenerarViaje", camposValores, errorMensaje, "Viaje registrado correctamente");

                ejecucion.Exec();
                if (!ejecucion.huboError())
                    limpiar();
            }
        }
开发者ID:GastonTS,项目名称:gdd-tp-2015,代码行数:32,代码来源:FormGenerarViaje.cs

示例6: Show

 void Show(string title, string text, Control control, ICON icon = 0, double timeOut = 0, bool allowMulti = false, bool focus = false, short x = 0, short y = 0)
 {
     if (!allowMulti)
         CloseAll();
     if (x == 0 && y == 0)
     {
         x = (short)(control.RectangleToScreen(control.ClientRectangle).Left + control.Width / 2);
         y = (short)(control.RectangleToScreen(control.ClientRectangle).Top + control.Height / 2);
     }
     TOOLINFO toolInfo = new TOOLINFO();
     toolInfo.cbSize = (uint)Marshal.SizeOf(toolInfo);
     toolInfo.uFlags = 0x20; // TTF_TRACK
     toolInfo.lpszText = text;
     IntPtr pToolInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(toolInfo));
     Marshal.StructureToPtr(toolInfo, pToolInfo, false);
     byte[] buffer = Encoding.UTF8.GetBytes(title);
     buffer = buffer.Concat(new byte[] { 0 }).ToArray();
     IntPtr pszTitle = Marshal.AllocCoTaskMem(buffer.Length);
     Marshal.Copy(buffer, 0, pszTitle, buffer.Length);
     hWnd = User32.CreateWindowEx(0x8, "tooltips_class32", "", 0xC3, 0, 0, 0, 0, control.Parent.Handle, (IntPtr)0, (IntPtr)0, (IntPtr)0);
     User32.SendMessage(hWnd, 1028, (IntPtr)0, pToolInfo); // TTM_ADDTOOL
     User32.SendMessage(hWnd, 1042, (IntPtr)0, (IntPtr)((ushort)x | ((ushort)y << 16))); // TTM_TRACKPOSITION
     //User32.SendMessage(hWnd, 1043, (IntPtr)0, (IntPtr)0); // TTM_SETTIPBKCOLOR
     //User32.SendMessage(hWnd, 1044, (IntPtr)0xffff, (IntPtr)0); // TTM_SETTIPTEXTCOLOR
     User32.SendMessage(hWnd, 1056, (IntPtr)icon, pszTitle); // TTM_SETTITLE 0:None, 1:Info, 2:Warning, 3:Error, >3:assumed to be an hIcon. ; 1057 for Unicode
     User32.SendMessage(hWnd, 1048, (IntPtr)0, (IntPtr)500); // TTM_SETMAXTIPWIDTH
     User32.SendMessage(hWnd, 0x40c, (IntPtr)0, pToolInfo); // TTM_UPDATETIPTEXT; 0x439 for Unicode
     User32.SendMessage(hWnd, 1041, (IntPtr)1, pToolInfo); // TTM_TRACKACTIVATE
     Marshal.FreeCoTaskMem(pszTitle);
     Marshal.DestroyStructure(pToolInfo, typeof(TOOLINFO));
     Marshal.FreeCoTaskMem(pToolInfo);
     if (focus)
         control.Focus();
     control.Enter += control_Event;
     control.Leave += control_Event;
     control.TextChanged += control_Event;
     control.KeyPress += control_Event;
     control.Click += control_Event;
     control.LocationChanged += control_Event;
     control.SizeChanged += control_Event;
     control.VisibleChanged += control_Event;
     if (control is DataGridView)
         ((DataGridView)control).CellBeginEdit += control_Event;
     Control parent = control.Parent;
     while(parent != null)
     {
         parent.VisibleChanged += control_Event;
         parent = parent.Parent;
     }
     control.TopLevelControl.LocationChanged += control_Event;
     ((Form)control.TopLevelControl).Deactivate += control_Event;
     timer.AutoReset = false;
     timer.Elapsed += timer_Elapsed;
     if (timeOut > 0)
     {
         timer.Interval = timeOut;
         timer.Start();
     }
 }
开发者ID:ddonny,项目名称:Network-Manager,代码行数:59,代码来源:BalloonTip.cs

示例7: ModelCamera

 public ModelCamera(Control focusControl, ControlRender dev)
 {
     mControl = focusControl;
     focusControl.MouseClick += (obj, e) => focusControl.Focus();
     mDevice = dev.Device;
     mInput = dev.InputManager;
     mDevice.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, Vector3.Zero, Vector3.UnitZ));
 }
开发者ID:remixod,项目名称:sharpwow,代码行数:8,代码来源:ModelCamera.cs

示例8: EmptyPrivateKeyField

        private void EmptyPrivateKeyField(Control focusControl)
        {
            PrivateKey.PasswordChar = (char)0;
            PrivateKey.Text = _enterPhrase;
            PrivateKey.TextAlign = HorizontalAlignment.Center;
            PrivateKey.ForeColor = Color.LightGray;

            focusControl.Focus();
        }
开发者ID:anonghosteam,项目名称:outlook-privacy-plugin,代码行数:9,代码来源:Passphrase.cs

示例9: TryFocusInvalidInput

 public static bool TryFocusInvalidInput(ErrorProvider errorProvider, Control control)
 {
     if (!string.IsNullOrEmpty(errorProvider.GetError(control)))
     {
         control.Focus();
         return true;
     }
     return false;
 }
开发者ID:imrekoszo,项目名称:munkanaplo,代码行数:9,代码来源:FormHelpers.cs

示例10: LoadProcessInControl

        public static void LoadProcessInControl(string _Process, Control _Control)
        {
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(_Process);
            p.WaitForInputIdle();

            _Control.Focus();
            Native.SetParent(p.MainWindowHandle, _Control.Handle);
            ShowWindow(p, SW_SHOWMAXIMIZED);
        }
开发者ID:ViniciusConsultor,项目名称:ptproject-pt,代码行数:9,代码来源:Native+.cs

示例11: Validate

 /// <summary>
 /// 验证所有的控件,如果失败弹出信息并重定位焦点
 /// </summary>
 /// <param name="ctr">被验证控件</param>
 /// <param name="message">验证失败弹出的消息</param>
 /// <returns>失败返回false,成功返回true</returns>
 public static bool Validate(Control ctr, string message)
 {
     bool result = Validate(ctr);
     if (!result)
     {
         MessageBoxHelper.Show(message);
         ctr.Focus();
     }
     return result;
 }
开发者ID:romanu6891,项目名称:fivemen,代码行数:16,代码来源:ValidatorHelper.cs

示例12: Focus

 //# __________ PROTOCOL :: PRIVATE __________ #//
 public void Focus(Control c)
 {
     c.Focus();
     if( c is TextBox ) ((TextBox)c).SelectAll();
     if( c is Button )
     {
         ButtonGotFocusType ev = _buttonFocusMap[(Button)c];
         if( ev != null ) ev();
     }
 }
开发者ID:pabplanalp,项目名称:pvmail,代码行数:11,代码来源:JwTabOrder.cs

示例13: AlertMessage

 private bool AlertMessage(string msg, Control txtObj)
 {
     if (!string.IsNullOrEmpty(msg))
     {
         pnlLoading.Controls.Add(LoadingCtrl.LoadModel(MessageType.Error, msg));
         txtObj.Focus();
         return false;
     }
     return true;
 }
开发者ID:jeanmahai,项目名称:28helpmate,代码行数:10,代码来源:GetPwd.cs

示例14: ShowView

 public void ShowView(IView view) {
     if (_View != null) {
         Controls.Remove(_View);
         _View = null;
     }
     _View = view as Control;
     Controls.Add(_View);
     _View.Dock = DockStyle.Fill;
     _View.Focus();
 }
开发者ID:darrelmiller,项目名称:RESTAgent.Samples,代码行数:10,代码来源:ShellForm.cs

示例15: ErreurSaisie

 public static void ErreurSaisie(Control txtSaisie, string message)
 {
     // affichage des messages d'erreur avec mise en évidence de l'erreur
     MessageBox.Show(message);
     if (txtSaisie is TextBox)
     { 
         ((TextBox)txtSaisie).SelectionStart = 0;
         ((TextBox)txtSaisie).SelectionLength = txtSaisie.Text.Length;
     }
     txtSaisie.Focus();
 }
开发者ID:MrStamina,项目名称:CorrectionProjetForfait,代码行数:11,代码来源:Affichage.cs


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