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();
                    }
                }
            }
  • 相关阅读:
    python中 __new__和__init__
    生成器
    边缘与轮廓
    霍夫变换
    高级滤波
    基本形态学滤波
    基本图形的绘制(基于skimage)
    图像的自动阈值分割
    图像的简单滤波
    直方图与均衡化
  • 原文地址:https://www.cnblogs.com/jcdd-4041/p/3363068.html
Copyright © 2011-2022 走看看