PageRenderTime 50ms CodeModel.GetById 23ms 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
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace System.Windows.Forms
  6. {
  7. public class WinForm
  8. {
  9. //http://www.codeproject.com/Articles/44928/FindControl-for-Windows-Forms
  10. public static Control FindControl(Control root, string target)
  11. {
  12. if (root.Name.Equals(target))
  13. return root;
  14. for (var i = 0; i < root.Controls.Count; ++i)
  15. {
  16. if (root.Controls[i].Name.Equals(target))
  17. return root.Controls[i];
  18. }
  19. for (var i = 0; i < root.Controls.Count; ++i)
  20. {
  21. Control result;
  22. for (var k = 0; k < root.Controls[i].Controls.Count; ++k)
  23. {
  24. result = FindControl(root.Controls[i].Controls[k], target);
  25. if (result != null)
  26. return result;
  27. }
  28. }
  29. return null;
  30. }
  31. public static void RemoveFocus(Control ctrl)
  32. {
  33. Button btn = new Button();
  34. btn.Parent = ctrl;
  35. btn.Left = -9999;
  36. btn.Top = -9999;
  37. btn.Focus();
  38. btn.Dispose();
  39. }
  40. }
  41. }