zoukankan      html  css  js  c++  java
  • 在form窗体里面 寻找当前焦点的控件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace PrintDatas
    {
        public static class SelectFocusInControls
        {
            // DLL调用注册  
            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)]
            private static extern IntPtr GetFocus();
            /// <summary>  
            /// 当前拥有焦点的控件  
            /// </summary>  
            public static Control GetFocusedControl(this Control formControl)
            {
                Control focusedControl = null;
                try
                {
                    IntPtr focusedHandle = GetFocus();
                    if (focusedHandle != IntPtr.Zero)
                        focusedControl = Control.FromChildHandle(focusedHandle);
                }
                catch { }
                return focusedControl;
            }
        }
    }
    /// <summary>  
            ///  设置当前获得焦点的控件的下一控件(Tab顺序)为当前焦点控件  
            /// </summary>  
            public static void SetNextControlFocused(this Control formControl)
            {
                Control ctlFocused = GetFocusedControl(formControl);
                if (ctlFocused != null)
                {
                    Control ctl = formControl.FindForm().GetNextControl(ctlFocused, false);
                    if (ctl == null)
                    {
                        ctl = formControl.FindForm().GetNextControl(ctlFocused, true);
                    }
                    if (ctl != null)
                    {
                        ctl.Focus();
                    }
                }
            }
  • 相关阅读:
    25-网易新闻iOS版使用的开源组件
    03-Xcode 6 插件失效的临时解决方案
    01-CEO才是天花板
    01-微信6.2
    01-创业视频
    03-http2翻译在线文档
    02-iOS核心动画-第一课——ViewAnimations
    24-Xcode快捷键
    02-IOS项目开发代码规范标准
    03-iOS Socket用法
  • 原文地址:https://www.cnblogs.com/jcdd-4041/p/3363068.html
Copyright © 2011-2022 走看看