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();
                    }
                }
            }
  • 相关阅读:
    write to logfile
    open and read a file content to a variable
    strategy
    Android 开机启动程序
    消息队列
    卡机音乐功能实现
    Android 2.0 开机动画文件分析
    多线程实例
    消息队列
    多线程实例
  • 原文地址:https://www.cnblogs.com/jcdd-4041/p/3363068.html
Copyright © 2011-2022 走看看