Archive

Archive for September, 2009

Converting a Hexadecimal Color to a System.Drawing.Color Object

September 24th, 2009 No comments

I try to avoid setting styles in my code as much as possible. However, I ran across a case using a DevExpress PageControl control where there was no possible way to set a certain border by using CSS. This is because DevExpress wisely (read sarcasm) uses “border-color: #whatever !important” in the element’s style attribute. So, there is no way to override that style except by setting it on the control in code (or your aspx page).

The particular border I needed is the ContentStyle.Border border of the ASPxPageControl and I needed to set the BorderColor property which is a System.Drawing.Color object. There isn’t any straightforward way to get a Color object from a hexadecimal color using the Color object itself. You have to use the ColorTranslator (also in the System.Drawing namespace) which gives you a FromHtml method and returns the correct Color object.

Color hexColor = ColorTranslator.FromHtml(“#666666″);

Thanks to this guy for the quick answer: http://www.akxl.net/labs/articles/converting-a-hexadecimal-color-to-a-system.drawing.color-object/

Replacing newline characters in VB.NET strings

September 1st, 2009 No comments
September 1st, 2009 | Categories: SQL Server 2008VB.NET | Tags: 

I’m not very familiar (which I am actually very happy for!) with VB.NET and so I had a hard time figuring out how to trim newline characters from a string in a Reporting Services report I was working on.

Turns out none of the “regular” methods really work.  The Trim function only removes spaces and anything like Replace(“string”, “\n”, “”) didn’t work.

You have to use the Chr(13) or Chr(10) functions to actually get the character values for the newline characters.  So, my solution looked like this:

Replace(Replace(stringVariable, Chr(10), “”), Chr(13), “”)

Thanks to this forum post for providing the clues: http://www.daniweb.com/forums/thread54797.html

Categories: VB.NET Tags: , , , , ,