PageRenderTime 44ms CodeModel.GetById 41ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/HtmExplorer_Src/CommonControl/FILE/System.cs

https://github.com/450640526/HtmExplorer
C# | 44 lines | 40 code | 3 blank | 1 comment | 7 complexity | 1f0f80f19488d3eb6dbfccc8694dd78a MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5
 6namespace System.Windows.Forms
 7{
 8    public class WinForm
 9    {
10        //http://www.codeproject.com/Articles/44928/FindControl-for-Windows-Forms
11
12        public static Control FindControl(Control root, string target)
13        {
14            if (root.Name.Equals(target))
15                return root;
16            for (var i = 0; i < root.Controls.Count; ++i)
17            {
18                if (root.Controls[i].Name.Equals(target))
19                    return root.Controls[i];
20            }
21            for (var i = 0; i < root.Controls.Count; ++i)
22            {
23                Control result;
24                for (var k = 0; k < root.Controls[i].Controls.Count; ++k)
25                {
26                    result = FindControl(root.Controls[i].Controls[k], target);
27                    if (result != null)
28                        return result;
29                }
30            }
31            return null;
32        }
33
34        public static void RemoveFocus(Control ctrl)
35        {
36            Button btn = new Button();
37            btn.Parent = ctrl;
38            btn.Left = -9999;
39            btn.Top = -9999;
40            btn.Focus();
41            btn.Dispose();
42        }
43    }
44}