Bitwise operations on Enum Flags

Thursday, October 26, 2006 9:13:37 PM (Central Standard Time, UTC-06:00)

A number of times I find my self looking up how to assign multiple enum values to a property to support options semantics on a control.  So to make it easier to find I am TidByteing it here. An example of this is the classic Border property that allows you to identify where you want lines drawn.  For example, lets say we have an enum that looks like this (note that I am using powers of two so they can easily be combined):

public enum Border

       {

           Top = 1,

           Bottom = 2,

           Left = 4,

           Right = 8

       }

And you want to indicate to draw only on the left and right borders would look something like this:

ctl.Border = Border.Left | Border.Right

To make this work you need to add the FlagsAttribute to the enum:

[Flags()]
public enum Border

 

Then to check to see if a flag is set you would do the following:

if ((propertyName & Border.Left) == Border.Left)

        //border left border needs to be drawn;

 

 

MSDN Article - Smart Clients: Essential Requirements and Candidate Services

Tuesday, October 17, 2006 10:31:13 PM (Central Standard Time, UTC-06:00)

I collaborated on an article for Smart Client architecture called "Smart Clients: Essential Requirements and Candidate Services".  It was published out on MSDN not too long ago.  

Microsoft Collaborative Workspace

Tuesday, October 17, 2006 9:27:17 PM (Central Standard Time, UTC-06:00)

I am out in Redmond this week and got to see the Patterns & Practices work area.  You can see what it looks like on Channel9.  One of the things that I noticed was the monitor arms they have....

Humanscale M7 Monitor Arm  (Build-Your-Own) Desk Mount - Wall Mount

I know it seems a little weird... you have to understand I am looking for Nirvana from a monitor standpoint.  I have a couple of monitor arms mounted in my home office... but I am constantly dealing with trying to get it from rotating down and doing a face plant on my desk.  No matter how tight I get the securing bolt... it slips and I have to constantly deal with it.  I Don't have the capability to move the monitors vertical either.  The setup I saw today look solid... you could move it up down, forward back and tilt and it all seemed pretty solid.  I got the model and brand while I was there.  They are using HumanScale's M7... you can get a better idea of what I am talking about by looking at the options to order one of these. 

I priced out a configuration that would nearly work with my current configuration of monitors... might have to rethink my configuration though it was $647 for 4 monitor support with all the extensions. Ouch.

Google CodeSearch

Wednesday, October 11, 2006 3:03:12 PM (Central Standard Time, UTC-06:00)

Google introduced Code Search about a week ago.  It doesn't look like it actually will pull code snippets from blogs or html, but it pulls from sources that are not typically cataloged by crawlers... such as archive files.  I have already found it useful a number of times.

Lets say you want a function to convert a string to pascal case... you know this function has been written a thousands times before so you hit Google.

Google Search on 'c# pascalcase'

There is a bunch of hits on coding standards but no function that actually converts a string to pascal case on the first page.

Now try it on code search...

Google Code Search on 'lang:c# pascalcase'

Right away you find the code you are looking for.

Xml Notepad is back...

Wednesday, October 11, 2006 3:02:28 PM (Central Standard Time, UTC-06:00)

For those that loved (may be a bit strong... maybe liked... it wasn't that great) Xml Notepad in the late 90's they have released an updated version.

DasBlog 1.9 now supports posting images through Live Writer

Friday, October 06, 2006 1:26:55 PM (Central Standard Time, UTC-06:00)

Anyone that uses Live Writer will be happy to know that you can post images on your blog without using FTP.

Problems with the Draw() on the IHMTLPainter interface

Friday, October 06, 2006 1:24:29 PM (Central Standard Time, UTC-06:00)

The project that I am working on right now we are making some customizations to the MSHTML editor that is hosted by Internet Explorer.  With that we have some custom tags that we need rendered in a specific way (for example wavy lines under misspelled words). 

This can be accomplished by a Binary Behavior that implements the IHTMLPainter interface.  When the behavior is loaded, MSHTML checks to see if the IHTMLPainter interface is supported, if it is supported it will call the appropriate methods on the interface to render the tag. 

The problem I was having was the Draw method was never called.  I could attach the behavior to the body tag and it would render the graphics I wanted, but as soon as a moved it to a span it wouldn't call the draw.  After a couple of hours playing around with it I finally stumbled on to the fact that if the span has a height and width set (even to 0) the Draw() method will be called.  I didn't find this documented anywhere so I thought I would post it for others.

Learn more about binary behaviors here.