forked from ctacke/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormsExtensions.cs
37 lines (33 loc) · 949 Bytes
/
FormsExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace System.Windows.Forms
{
#if WindowsCE
public static class FormsExtensions
{
public static void RemoveByKey(this Control.ControlCollection collection, string key)
{
if (!RemoveChildByName(collection, key))
{
throw new ArgumentException("Key not found");
}
}
private static bool RemoveChildByName(this Control.ControlCollection collection, string name)
{
foreach (Control child in collection)
{
if (child.Name == name)
{
collection.Remove(child);
return true;
}
// iterate children
if (RemoveChildByName(child.Controls, name)) return true;
}
return false;
}
}
#endif
}