Daily using/supporting

Get Firefox browser!
Get Thunderbird!
Get Opera browser!
Get The Gimp!
Get Inkscape!
Get LibreOffice!
Get Videolan!
Get Linux!
Get Mandriva!
Get Joomla!
Hacker Emblem

Archives

Which topics would you like us to cover more?

Latest comments

Latest tweets

about 1 day ago Using REDIPS.drag to add drag and drop to your .Net webapplication #li #dib0 http://t.co/n8zY3s7d
about 7 days ago http://t.co/cknQcDbo #Kindle
about 15 days ago Freedom isn't the ability to choose what to do or say, but the ability to choose what not to do or say #freedom
about 29 days ago http://t.co/61KTQknI #Kindle
12 Apr 2012 Force the use of a networking adapter using C# #li #dib0 http://t.co/ZTJOPzOz
9 Apr 2012 Mandriva 2010.2 and USB devices in Virtualbox http://t.co/fwq9gbHB
9 Apr 2012 Execute a http request to you own site with PHP http://t.co/DIvWPrpd
Two extension methods
Written by Division by Zero   
Monday, 24 May 2010 08:44

While searching the archives for a coding solution I came across two extension methods. They worked for me so why couldn't some of you benefit from them.

The first one is a method for recursively finding a control on a page. I still think that there must be a better way to do this,but I haven't found it yet. If you have any suggestions: let me know!

 
public static Control DeepFindControlById(this Page page, string id)
{
 return DeepFindControl(page.Controls, id);
}

private static Control DeepFindControl(ControlCollection controls, string id)
{
 Control result = null;

 bool found = false;
 for (int i = 0; (i < controls.Count) && (!found); i++)
 {
 if (string.Compare(controls[i].ID, id) == 0)
 {
 found = true;
 result = controls[i];
 }
 else
 {
 // if the control has childcontrols, recursive search
 if (controls[i].HasControls())
 {
 result = DeepFindControl(controls[i].Controls, id);

 found = (result != null);
 }
 }
 }

 return result;
}

The other one is a simple one that blends two colors.

 
/// 
/// Blend the two colors
/// 
///
Base color
///
Mixing color
/// New color
public static Color Blend(this Color color1, Color color2)
{
 byte r = Convert.ToByte(Math.Min((color1.R + color2.R) / 2, 255));
 byte g = Convert.ToByte(Math.Min((color1.G + color2.G) / 2, 255));
 byte b = Convert.ToByte(Math.Min((color1.B + color2.B) / 2, 255));

 return Color.FromArgb(r, g, b);
}
 

Add comment


Security code
Refresh

He's the only genius with an IQ of 80. - Unknown


© 2009 - 2012, Division by Zero

Template based on the empire template by joomlashack 

Valid XHTML 1.0 Strict  Valid CSS!  Creative Commons License
This work by Division by Zero is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.