Skip to main content

Posts

Showing posts from August, 2018

Winforms + Transparent Background? LimeGreen? AliceBlue?

For starters, winforms will complain that you cannot set the background of the form to transparent. After a little digging, I found on a stack over flow  post that you can set the background to an obscure colour like limegreen. Lo and behold, we have a properly transparent form. I was using this for a quick and dirty way to select an area to screen capture. However there is one issue. The transparent form results in the click events going through to what ever is underneath it. As illustrated in the screen shot above, you can select text directly underneath it. This is pretty cool, especially if TopMost is set to true. However...the grip resize was also not being triggered. In other words, I cannot resize the new form. If the grip was on top of the parent form, then the resize event would work.  I tried a few approaches, such as intercepting the hittest, a few interops. But in the end the solution was quite simple.If you set the background colour to AliceBlue...

Parsing XML - Quick 'n Dirty

LINQ can be used to dynamically and quickly parse XML. The following data can be read in like so: 1 2 3 4 5 6 7 8 9 10 <root> <Element> <Name> ..... </Name> <Height> ..... </Height> </Element> <Element> <Name> ..... </Name> <Height> ..... </Height> </Element> </root> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 XDocument doc = XDocument .Load( "file.xml" ); var collection = from r in doc.Descendants( "Element" ) select new { Name = r.Element( "Name" ).Value, Height = r.Element( "Height" ).Value, }; foreach ( var element in collection) { // Properties can be accessed like an object // element.Name; // element.Height; }