Nitriq is a product by


Accessing The Control Responsible For A ContextMenuStrip
 
It certainly isn't easy to access what winform control was ultimately responsible for bringing up a ContextMenuStrip, but it is indeed possible, there is just some casting involved :)


private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
    if (((ContextMenuStrip)((ToolStripMenuItem)sender).Owner).SourceControl ==
        this.PrimeNumbersCheckBoxList)
    {
        this.SelectAllThePrimeNumbers();
    }
   
    if (((ContextMenuStrip)((ToolStripMenuItem)sender).Owner).SourceControl ==
        this.CompositeNumbersCheckBoxList)
    {
        this.SelectAllTheCompositeNumbers();
    }
}



Thursday, December 27, 2007 - 5:06 PM CST - Permalink - Comments [0]
Tags: Tips and Tricks


How To Easily Add A DotNetKicks Button To DasBlog
 
It is incredibly easy to add a DotNetKicks "Kick It" Button to any DasBlog website. Simply navigate to your "themes" directory and open up the "itemTemplate.blogtemplate" file with text editor. And simply paste the following HTML wherever you'd like the button to display.

<a href="http://www.dotnetkicks.com/kick/?url=<%PermalinkUrl%>"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=<%PermalinkUrl%>" border="0" alt="kick it on DotNetKicks.com" /></a>

Pretty simple, huh? Thanks to John Forsythe for posting all the available DasBlog Macros.

If you're thinking about starting a blog, I highly recommend DasBlog, it was a very easy to setup, especially since it doesn't require a database! That makes the cost of hosting a blog at DiscountAsp.net only $10/month! Subtext on the other hand needs a database to store and will run you $20 a month. I don't really know why DasBlog doesn't advertise that fact more, I would have tried installing it first, is a relational database really that necessary for a blog? It also makes it brain dead simple to backup your blog or move hosting providers. I know because I started out hosting my blog at 1and1 (stay away!), I've been with DiscountAsp.net for a couple months and absolutely love it. Everything just works, I copied my DasBlog files over and I was done. Plus its cheap and since all they do is focus on Microsoft technologies, they always have the latest and greatest beta stuff running as soon as it comes out (like .Net 3.5 and IIS 7.0).


Monday, December 17, 2007 - 8:03 PM CST - Permalink - Comments [1]
Tags: Tips and Tricks


Zune - Does NOT Play For Sure
 
So I was totally stoked when I won my new Zune last night, I've been using Rhapsody for quite some time and have really enjoyed it thus far, but I was looking forward to using a device with it other than my Sansa e260. So tonight I fire up the rhapsody client app on my desktop, plug in my new Zune, and there is no "device" icon popping up in rhapsody (like there is with my Sansa). I think: oh, I wonder if I have to install the Zune software first for some bizzare driver, then the rhapsody client will be able to talk with my Zune. I install the Zune software, setup everything as necessary and then start the rhapsody client. Nothing, still. Shit. I google "Zune Plays For Sure", thinking that surely, Microsoft after spending millions of dollars coming up with PlaysForSure. But no, Zune only works with the Zune Marketplace, not even music from the MSN MUSIC STORE will play on a Zune.

Microsoft: I really am a big fan, a "fanboy" would probably be an acurate description of my opinion on your company. I know that you're going through kind of an image problem, people don't seem to be (or say at least) that they're usually satisfied with you as a company. Here is why: people have a bad experience with one of your products and that one experience colors their entire perception. It sucks to be in that position because it puts a lot of pressure to have everything be top-notch, a difficult glass to fill. I'm still a "fanboy". Your office productivity tools: Second-To-None. Your developer tools: Awesome. Your development frameworks: Magnificent. Your gaming console: Pretty Bad Ass. I know that having the best product isn't going to be possible, but for the love of God, having the Zune support PlaysForSure is a NO BRAINER. This has really left a bad taste in my mouth, I'm going gargle with some Minty Blend to get rid of it.


Thursday, December 13, 2007 - 10:53 PM CST - Permalink - Comments [2]
Tags:


Game Of Life Demo
 
Thanks to everyone who came to the IADNUG install-fest last night. I received a 8GB Zune and second place with my Game of Life Demo. Thanks to Microsoft and Mike Benkovich for supplying the prizes, I thoroughly look forward to using my new Zune. Mike should have a post at BenkoTIPS that will link to the other contestants projects (if they're allowed to release them).

As promised, I've posted a link to the code I demo'd last night. It's a little messy because I was more concerned with getting functionality and a pretty front-end than in producing pretty code. I do, however intend on continuing work on it as a hobby project, I think I've got a lot of neat ideas for new directions to take the project. So if you're interested in staying updated, either subscribe to my "Projects" RSS feed, or feel free to leave a comment with your email address and I'll be sure to send you a note when I post a new version.



Thanks again to everyone who came.

GameOfLifeWpf.zip (191.98 KB)

Note: When launching the 3D Form, you have to click on the "Cube" button first, before you can hit start.

Thursday, December 13, 2007 - 9:25 AM CST - Permalink - Comments [1]
Tags: IADNUG | Projects


Blend Tutorial Videos
 
I've been working a lot lately on a demo for tomorrow night's VS 2008 Installfest Event. I plan on posting my code after the demo (because I probably won't be done until right before I have to present), but I wanted to let everyone know what tutorials I used to help create my demo. Expression Blend is frickin awesome, I had been dabling in WPF a little bit, but not a whole lot was "clicking", but I had about 12 "A-HA" moments while watching these videos. Highly recommended, especially if you're visual learner.

Channel 9: Introduction to Blend (Part 1) (Part 2) (Part 3) (Part 4)

Way to go Mike Grayson and Richard Godfrey.


Tuesday, December 11, 2007 - 8:18 PM CST - Permalink - Comments [0]
Tags: Blend | IADNUG


Black vs White Text
 
Whether it is a heat map or a simple legend on a graph, color has the uncanny ability to instantly convey to users the intricacies of their data. But like most powerful constructs, color can easily be misunderstood and abused. I highly recommend that all GUI developers read up on all the crazy (and cool) things you can do to manipulate colors.

Last year I spent a fair amount of time scouring the net trying to find a solution to a frequently experienced problem: background - foreground color readability. And for the most part I came up empty handed, so I did even more digging and researching and have found the optimal way of determining whether white or black text will look best on an arbitrary background color. At first I tried solely looking at the "V" component of the HSV color space, but that would dictate the I use black text on a blue background (which doesn't work).

I tried making my own custom metrics like if (R + G + B)/(255 * 3) was greater than 1/2 then use black, else white, but when you test the results, it just doesn't seem to work all that well. The problem lies with the human eye, while the monitor has a certain color addressing space, people actually perceive color differently. It makes sense when you think about it, for most of homo sapiens history have primarily looked at all the green vegitation surrounding us; so naturally the human eye is more perceptive to shades of green than red or blue. After some extra long digging, I stumbled upon the YIQ color space, where "Y" is the luma a.k.a. perceived luminance. The formula for calculating Y from RGB is Y = 0.299 * R + 0.587 * G + 0.114 * B

We can now calculate the maximum perceived luminance of white (0.299 * 255 + 0.587 * 255 + 0.114 * 255) and the midpoint at which something is "half-bright" by dividing the max into 2. Because I'm calculating values relative to one another, I simply made each color coefficient a whole integer to make an infinitesimally small difference in performance. You should try it out, it works really well.


//perceived luminance
private const int RED_LUMINANCE = 299;
private const int GREEN_LUMINANCE = 587;
private const int BLUE_LUMINANCE = 114;
//calculated from http://en.wikipedia.org/wiki/Luminance(video)
private const int MAX_LUMINANCE = (RED_LUMINANCE * 255 + GREEN_LUMINANCE * 255 + BLUE_LUMINANCE * 255);
private const int MID_LUMINANCE = MAX_LUMINANCE / 2;

/// <summary>
/// Finds the foreground (white or black) that will be easiest to read
/// with the given background
/// </summary>

public static Color CalculateForeColor(Color backColor)
{
    int totalCustomBrightness =
        ((backColor.R * RED_LUMINANCE) + (backColor.G * GREEN_LUMINANCE) + (backColor.B * BLUE_LUMINANCE));

    if (totalCustomBrightness <= MID_LUMINANCE)
        return Color.White;
    else
        return Color.Black;
}



Thursday, December 6, 2007 - 10:01 PM CST - Permalink - Comments [0]
Tags: Design | Tips and Tricks