<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://saguiitay.spaces.live.com/mmm2008-05-17_13.22/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fsaguiitay.spaces.live.com%2fcategory%2fGUI%2bDevelopment%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Itay's space: GUI Development</title><description /><link>http://saguiitay.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catGUI%2bDevelopment</link><language>en-US</language><pubDate>Wed, 23 Jul 2008 03:21:52 GMT</pubDate><lastBuildDate>Wed, 23 Jul 2008 03:21:52 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://saguiitay.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>4287375271627483618</live:id><live:alias>saguiitay</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>ListViewGroup - only one item per group</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!768.entry</link><description>&lt;p&gt;As I was working on a new GUI part of the software I'm working on, I needed to allow the user to choose only a single item in each category. I overloaded the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.aspx" target="_blank"&gt;ListView&lt;/a&gt; control, and override the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.onitemcheck.aspx" target="_blank"&gt;OnItemCheck&lt;/a&gt; method. Here's the result: &lt;p&gt;&lt;font face="Courier New" size=2&gt;&lt;font color="#0000ff"&gt;public class&lt;/font&gt; &lt;font color="#0080ff"&gt;SingleItemPerGroupListView&lt;/font&gt; : &lt;font color="#0080ff"&gt;ListView&lt;/font&gt;&lt;br&gt;{&lt;br&gt;    &lt;font color="#0000ff"&gt;public&lt;/font&gt; SingleItemPerGroupListView()&lt;br&gt;    { } &lt;/font&gt; &lt;p&gt;&lt;font face="Courier New" size=2&gt;    &lt;font color="#0000ff"&gt;protected override void&lt;/font&gt; OnItemCheck(&lt;font color="#0080ff"&gt;ItemCheckEventArgs&lt;/font&gt; ice)&lt;br&gt;    {&lt;br&gt;        &lt;font color="#008000"&gt;// Always behave regulary when user uncheck an item&lt;br&gt;&lt;/font&gt;        &lt;font color="#0000ff"&gt;if&lt;/font&gt; (ice.NewValue == &lt;font color="#0080ff"&gt;CheckState&lt;/font&gt;.Unchecked)&lt;br&gt;        {&lt;br&gt;            &lt;font color="#0000ff"&gt;base&lt;/font&gt;.OnItemCheck(ice);&lt;br&gt;            &lt;font color="#0000ff"&gt;return&lt;/font&gt;;&lt;br&gt;        } &lt;/font&gt; &lt;p&gt;&lt;font face="Courier New" size=2&gt;        &lt;font color="#008000"&gt;// Get the checked item&lt;br&gt;&lt;/font&gt;        &lt;font color="#0080ff"&gt;ListViewItem&lt;/font&gt; lvi = &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Items[ice.Index]; &lt;/font&gt; &lt;p&gt;&lt;font face="Courier New" size=2&gt;        &lt;font color="#008000"&gt;// If no item has no group, handle regulary&lt;br&gt;&lt;/font&gt;        &lt;font color="#0000ff"&gt;if&lt;/font&gt; (lvi.Group == &lt;font color="#0000ff"&gt;null&lt;/font&gt;)&lt;br&gt;        {&lt;br&gt;            &lt;font color="#0000ff"&gt;base&lt;/font&gt;.OnItemCheck(ice);&lt;br&gt;            &lt;font color="#0000ff"&gt;return&lt;/font&gt;;&lt;br&gt;        } &lt;/font&gt; &lt;p&gt;&lt;font face="Courier New" size=2&gt;        &lt;font color="#008000"&gt;// If another item is checked, uncheck item&lt;br&gt;&lt;/font&gt;        &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#0080ff"&gt;ListViewItem&lt;/font&gt; otherLvi &lt;font color="#0000ff"&gt;in&lt;/font&gt; lvi.Group.Items)&lt;br&gt;        {&lt;br&gt;            &lt;font color="#0000ff"&gt;if&lt;/font&gt; (otherLvi == lvi)&lt;br&gt;                &lt;font color="#0000ff"&gt;continue&lt;/font&gt;; &lt;/font&gt; &lt;p&gt;&lt;font face="Courier New" size=2&gt;            &lt;font color="#0000ff"&gt;if&lt;/font&gt; (otherLvi.Checked)&lt;br&gt;            {&lt;br&gt;                otherLvi.Checked = &lt;font color="#0000ff"&gt;false&lt;/font&gt;;&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/font&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+ListViewGroup+-+only+one+item+per+group&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!768.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!768.entry</guid><pubDate>Wed, 01 Aug 2007 22:13:25 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!768/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!768.entry#comment</wfw:comment><dcterms:modified>2007-08-01T22:13:25Z</dcterms:modified></item><item><title>Updating GUI from different threads - Part 2</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!666.entry</link><description>&lt;div&gt;As part of my work at &lt;a href="http://www.tzunami.com/"&gt;Tzunami Inc.&lt;/a&gt;, I'm working on migrating our product Deployer - a &lt;a href="http://www.tzunami.com/products"&gt;SharePoint migration&lt;/a&gt; tool - from .Net 1.1 to .Net 2.0 and Visual Studio 2005.&lt;/div&gt;
&lt;div&gt;One of the first things we've encountered was the managed debugging assistants (MDA). I'll talk about the MDAs in a later entry, but for now, let's just say that those are exceptions that are thrown only in debug mode, and that assist you in finding bugs and problematic points in your code that are otherwise hard to locate.&lt;/div&gt;
&lt;div&gt;The first MDA that we've encountered was the &amp;quot;Cross-thread operation not valid&amp;quot;. What this means, is that you're trying to update the GUI from a thread other than the thread that created the GUI control. You can read about how to solve this issue in .Net 1.1 in one of my previous entries.&lt;/div&gt;
&lt;div&gt;However, .Net 2.0 allows you to resolve this in a much cleaner way. Bellow is the way we decided to handle this:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;p&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;font size=2&gt;&lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; InvokeGuiDelegate(&lt;font color="#008080"&gt;GUIDelegate&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;font size=2&gt; d)&lt;br&gt;{&lt;br&gt;&lt;font color="#0000ff"&gt;    if&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New, Courier, Monospace" size=2&gt; (InvokeRequired)&lt;br&gt;&lt;font color="#0000ff"&gt;        &lt;/font&gt;BeginInvoke(d);&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New, Courier, Monospace" color="#0000ff" size=2&gt;    else&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;font size=2&gt;&lt;font color="#0000ff"&gt;        &lt;/font&gt;d();&lt;br&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;div&gt;Now we can use the above method everywhere we need to update the GUI, using an annonymous method:&lt;/div&gt;
&lt;p&gt;&lt;font size=2&gt;&lt;font face="Courier New, Courier, Monospace"&gt;InvokeGuiDelegate( &lt;/font&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;font color="#0000ff"&gt;delegate&lt;/font&gt;() { numericUDTimeout.Value = &lt;font color="#0000ff"&gt;value&lt;/font&gt;; });&lt;/font&gt;&lt;/font&gt;&lt;font size=1&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Updating+GUI+from+different+threads+-+Part+2&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!666.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!666.entry</guid><pubDate>Sun, 10 Sep 2006 11:57:41 GMT</pubDate><slash:comments>1</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!666/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!666.entry#comment</wfw:comment><dcterms:modified>2006-09-10T15:26:20Z</dcterms:modified></item><item><title>Fading form while moving</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!660.entry</link><description>&lt;div&gt;
&lt;p&gt;The different between a nice application and an exellent one, is many time only in the small details. How much did the developers really put into it? How much they thought about every detail?
&lt;p&gt;The following code is nothing more than an eye-candy, but we all know that it’s those simple things, that take seconds to write that make the difference.
&lt;p&gt;Let’s write 2 methods to increase and decrease the opacity of a window:
&lt;p&gt;&lt;code&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;font color="#0000ff"&gt;private void&lt;/font&gt; DecreaseOpacity()&lt;br&gt;{&lt;br&gt;&lt;font color="#0000ff"&gt;    while&lt;/font&gt; (&lt;font color="#0000ff"&gt;this&lt;/font&gt;.Opacity &amp;gt; 0.2)&lt;br&gt;    {&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;    &lt;/font&gt;    this&lt;/font&gt;.Opacity -= 0.02;&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;    &lt;/font&gt;    double&lt;/font&gt; lastOpacity = &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Opacity;&lt;br&gt;        Thread.Sleep(10);&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;    &lt;/font&gt;    if&lt;/font&gt; (&lt;font color="#0000ff"&gt;this&lt;/font&gt;.Opacity != lastOpacity)&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;      &lt;/font&gt;      break&lt;/font&gt;;&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;font color="#0000ff"&gt;private void&lt;/font&gt; IncreaseOpacity()&lt;br&gt;{&lt;br&gt;&lt;font color="#0000ff"&gt;    while&lt;/font&gt; (1 &amp;gt; &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Opacity)&lt;br&gt;    {&lt;br&gt;&lt;font color="#0000ff"&gt;    &lt;font color="#444444"&gt;    &lt;/font&gt;this&lt;/font&gt;.Opacity += 0.04;&lt;br&gt;        Thread.Sleep(10);&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/font&gt;&lt;/code&gt;Now, we want the form do fade out when the user moves it, and fade back in when he releases the form. For this, we’ll catch the &lt;font face="Courier New, Courier, Monospace"&gt;WM_ENTERSIZEMOVE &lt;/font&gt;and &lt;font face="Courier New, Courier, Monospace"&gt;WM_EXITSIZEMOVE &lt;/font&gt;messages of the window, and call the above methods in a different thread:
&lt;p&gt;&lt;code&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;font color="#0000ff"&gt;protected override void&lt;/font&gt; WndProc(&lt;font color="#0000ff"&gt;ref&lt;/font&gt; Message m)&lt;br&gt;{&lt;br&gt;&lt;font color="#0000ff"&gt;    switch&lt;/font&gt;(m.Msg)&lt;br&gt;    {&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;    &lt;/font&gt;    case&lt;/font&gt; (&lt;font color="#0000ff"&gt;int&lt;/font&gt;)0×231: &lt;font color="#008000" size=2&gt;//WM_ENTERSIZEMOVE&lt;/font&gt;&lt;br&gt;            Thread t = &lt;font color="#0000ff"&gt;new&lt;/font&gt; Thread(&lt;font color="#0000ff"&gt;new&lt;/font&gt; ThreadStart(DecreaseOpacity));&lt;br&gt;            t.Start();&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;      &lt;/font&gt;      break&lt;/font&gt;;&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;    &lt;/font&gt;    case&lt;/font&gt; (&lt;font color="#0000ff"&gt;int&lt;/font&gt;)0×232: &lt;font color="#008000" size=2&gt;//WM_EXITSIZEMOVE&lt;/font&gt;&lt;br&gt;            Thread t2 = &lt;font color="#0000ff"&gt;new&lt;/font&gt; Thread(&lt;font color="#0000ff"&gt;new&lt;/font&gt; ThreadStart(IncreaseOpacity));&lt;br&gt;            t2.Start();&lt;br&gt;&lt;font color="#0000ff"&gt;&lt;font color="#444444"&gt;      &lt;/font&gt;      break&lt;/font&gt;;&lt;br&gt;    }&lt;br&gt;&lt;font color="#0000ff"&gt;    base&lt;/font&gt;.WndProc(&lt;font color="#0000ff"&gt;ref&lt;/font&gt; m);&lt;br&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Fading+form+while+moving&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!660.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!660.entry</guid><pubDate>Wed, 06 Sep 2006 13:29:36 GMT</pubDate><slash:comments>9</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!660/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!660.entry#comment</wfw:comment><dcterms:modified>2006-09-06T13:29:36Z</dcterms:modified></item><item><title>Unbound items in a bound ComboBox</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!659.entry</link><description>&lt;div&gt;
&lt;p&gt;You are once again invited to read, reply and vote on my new article at &lt;a href="http://www.codeproject.com/"&gt;&lt;font color="#333333"&gt;CodeProject&lt;/font&gt;&lt;/a&gt;.
&lt;p&gt;The article demonstrates how to add unbound items to a bound ComboBox. The code uses a wrapper that implements the &lt;font face="Courier New, Courier, Monospace"&gt;IList &lt;/font&gt;interface, and supply the ComboBox both the extra items, that are kept at the beginning of the drop-down list, and the normal items, taken from the &lt;font face="Courier New, Courier, Monospace"&gt;DataSource&lt;/font&gt;.
&lt;p&gt;The article can be found here: &lt;a href="http://www.codeproject.com/useritems/UnboundItemsComboBox.asp"&gt;&lt;font color="#333333"&gt;http://www.codeproject.com/useritems/UnboundItemsComboBox.asp&lt;/font&gt;&lt;/a&gt; &lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Unbound+items+in+a+bound+ComboBox&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!659.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!659.entry</guid><pubDate>Wed, 06 Sep 2006 13:27:28 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!659/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!659.entry#comment</wfw:comment><dcterms:modified>2006-09-06T13:27:28Z</dcterms:modified></item><item><title>Filtering Win32 messages of a form</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!653.entry</link><description>&lt;div&gt;
&lt;p&gt;I've recently came across a nice post on &lt;a href="http://blogs.msdn.com/csharpfaq/default.aspx"&gt;&lt;font color="#333333"&gt;C# Frequently Asked Questions&lt;/font&gt;&lt;/a&gt; blog. In the post, they've shown a way to filter out, or (pre)process Win32 messages of a form. Let's have a look at the code, then we’ll go through it.
&lt;p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;public class &lt;/font&gt;MyMessageFilter : IMessageFilter&lt;br&gt;{&lt;br&gt;    &lt;font color="#0000ff"&gt;public bool &lt;/font&gt;PreFilterMessage(&lt;font color="#0000ff"&gt;ref &lt;/font&gt;Message m)&lt;br&gt;    {&lt;br&gt;        &lt;font color="#008000"&gt;// Intercept the left mouse button down message&lt;/font&gt;&lt;br&gt;        &lt;font color="#0000ff"&gt;if &lt;/font&gt;(m.Msg == 513)&lt;br&gt;        {&lt;br&gt;            Console.WriteLine(&amp;quot;WM_LBUTTONDOWN is: &amp;quot; + m.Msg);&lt;br&gt;            &lt;font color="#0000ff"&gt;return true&lt;/font&gt;;&lt;br&gt;        }&lt;br&gt;        &lt;font color="#0000ff"&gt;return false&lt;/font&gt;;&lt;br&gt;    }&lt;br&gt;}&lt;/code&gt;
&lt;p&gt;And in the form itself:
&lt;p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;public class &lt;/font&gt;mainForm : System.Windows.Forms.Form&lt;br&gt;{&lt;br&gt;    &lt;font color="#0000ff"&gt;private &lt;/font&gt;MyMessageFilter msgFliter = &lt;font color="#0000ff"&gt;new &lt;/font&gt;MyMessageFilter();
&lt;p&gt;    &lt;font color="#0000ff"&gt;public &lt;/font&gt;mainForm()&lt;br&gt;    {&lt;br&gt;        &lt;font color="#008000"&gt;// Register message filter&lt;/font&gt;&lt;br&gt;        Application.AddMessageFilter(msgFliter);&lt;br&gt;    }&lt;br&gt;}&lt;/code&gt;
&lt;p&gt;As you can see, we've started by creating a class that implements the &lt;font face="Courier New, Courier, Monospace"&gt;IMessageFilter &lt;/font&gt;interface. Then we've added an instance of that class to the form, and in the constructor registered it. We can use the &lt;font face="Courier New, Courier, Monospace"&gt;Application.RemoveMessageFilter() &lt;/font&gt;method to stop filtering messages using the specified filter. All the filter class does is handle the &lt;font face="Courier New, Courier, Monospace"&gt;WM_LBUTTONDOWN &lt;/font&gt;message. By returning true, we specify that we've handled the message, and there's no need of any further handling of it - meaning that no event will be sent. This technique can be used either as a way to handle specific messages, or just ignore certain messages. Other nice things to try is to catch the message only a certain amount of times, or to &amp;quot;hide&amp;quot; some of the messages when certain requirements are met. &lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Filtering+Win32+messages+of+a+form&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!653.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!653.entry</guid><pubDate>Wed, 06 Sep 2006 12:33:11 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!653/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!653.entry#comment</wfw:comment><dcterms:modified>2006-09-06T12:33:11Z</dcterms:modified></item><item><title>Transparent Click-thru windows</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!652.entry</link><description>&lt;div&gt;It is often usefull to provide the user with information on the screen, without interfering his work. Usually, you would just create a window with a somewhat lower opacity, allowing the user to see what’s beneath your window. However, this window will still receive all the normal windows events, and mostly, the user’s mouse clicks. To prevent this, all you have to do is override the window’s &lt;font face="Courier New, Courier, Monospace"&gt;&lt;code&gt;CreateParams&lt;/code&gt; &lt;/font&gt;accessor, and add to the &lt;font face="Courier New, Courier, Monospace"&gt;ExStyle &lt;/font&gt;property the &lt;code&gt;WS_EX_TRANSPARENT&lt;/code&gt; value. Let’s have a look: 
&lt;p&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;protected override&lt;/font&gt; CreateParams CreateParams&lt;br&gt;{&lt;br&gt;&lt;font color="#0000ff"&gt;    get&lt;/font&gt;&lt;br&gt;    {&lt;br&gt;        CreateParams cp = &lt;font color="#0000ff"&gt;base&lt;/font&gt;.CreateParams;&lt;br&gt;        cp.ExStyle |= 0×00000020;&lt;br&gt;&lt;font color="#0000ff"&gt;        return&lt;/font&gt; cp;&lt;br&gt;    }&lt;br&gt;}&lt;/code&gt; &lt;/font&gt;
&lt;div&gt;&lt;img alt="Transparent Click-thru window" src="http://saguiitay.wordpress.com/files/transparent.JPG"&gt;&lt;/div&gt;
&lt;p&gt; What you should notice in the about image, is that the “Save” button of the Visual Studio has the mouse hovering over it (hidden in the screent shot) and is highlighted.&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Transparent+Click-thru+windows&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!652.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!652.entry</guid><pubDate>Wed, 06 Sep 2006 12:23:34 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!652/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!652.entry#comment</wfw:comment><dcterms:modified>2006-09-06T15:06:22Z</dcterms:modified></item><item><title>Updating GUI from different threads</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!651.entry</link><description>&lt;div&gt;
&lt;p&gt;Even the smallest thing, when thought upfront, can help you go a long way. Whenever you create an application that is more that two forms thrown together, and that does a little bit more than just saying “Hello world”, you’ll encounter a point where you’ll want to use threads. So if you’re going to reach that point somewhere along the way, why not plan and prepare for that in advance?
&lt;p&gt;Working with threads by itself is not the really topic of this post. However, changing the GUI from different threads is. Windows applications in .Net request that changes in Forms be made in the thread that owns the form. Managing that on your own can be a real pain. Thanksfully, the .Net team thought about us, and allowed us a simple way to handle this:
&lt;p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;public void &lt;/font&gt;UpdateForm()&lt;br&gt;{&lt;br&gt;    &lt;font color="#0000ff"&gt;if &lt;/font&gt;(&lt;font color="#0000ff"&gt;this&lt;/font&gt;.InvokeRequired())&lt;br&gt;    {&lt;br&gt;        &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Invoke(&lt;font color="#0000ff"&gt;new &lt;/font&gt;MethodInvoker(UpdateForm));&lt;br&gt;        &lt;font color="#0000ff"&gt;return&lt;/font&gt;;&lt;br&gt;    }&lt;br&gt;    &lt;font color="#008000"&gt;// Update your form as usual here...&lt;br&gt;&lt;/font&gt;}&lt;/code&gt;
&lt;p&gt;The more attentive readers will raise the point, that this example works only because &lt;font face="Courier New, Courier, Monospace"&gt;UpdateForm()&lt;/font&gt; returns void and accepts no argument. Sadly this is true. For any other case we’ll have to write a delegate, and send the &lt;font face="Courier New, Courier, Monospace"&gt;Invoke()&lt;/font&gt; method an instance of that delegate, just as the following example shows:
&lt;p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;private delegate bool &lt;/font&gt;UpdateFormMethod(&lt;font color="#0000ff"&gt;int &lt;/font&gt;argument);&lt;/code&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;public bool &lt;/font&gt;UpdateForm(&lt;font color="#0000ff"&gt;int &lt;/font&gt;argument)&lt;br&gt;{&lt;br&gt;    &lt;font color="#0000ff"&gt;if &lt;/font&gt;(&lt;font color="#0000ff"&gt;this&lt;/font&gt;.InvokeRequired)&lt;br&gt;    {&lt;br&gt;        &lt;font color="#0000ff"&gt;return &lt;/font&gt;(&lt;font color="#0000ff"&gt;bool&lt;/font&gt;)&lt;font color="#0000ff"&gt;this&lt;/font&gt;.Invoke(&lt;font color="#0000ff"&gt;new &lt;/font&gt;UpdateFormMethod(UpdateForm),&lt;br&gt;            &lt;/code&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;new &lt;/font&gt;object[] {argument});&lt;br&gt;    }&lt;br&gt;&lt;font face="Courier New, Courier, Monospace"&gt;    &lt;/font&gt;&lt;font face="Courier New, Courier, Monospace" color="#008000"&gt;// Update your form as usual here...&lt;br&gt;&lt;/font&gt;    &lt;font color="#0000ff"&gt;return true&lt;/font&gt;;&lt;br&gt;}&lt;/code&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Updating+GUI+from+different+threads&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!651.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!651.entry</guid><pubDate>Wed, 06 Sep 2006 12:12:16 GMT</pubDate><slash:comments>2</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!651/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!651.entry#comment</wfw:comment><dcterms:modified>2006-09-06T12:12:16Z</dcterms:modified></item><item><title>Prevent changing the state of a CheckBox</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!648.entry</link><description>&lt;div&gt;
&lt;p&gt;Preventing an item in a CheckedListBox or a ListView with CheckBoxed is a really basic requirement when dealing with GUI. The simple and elegant code is for some reason, quite under-sampled.
&lt;p&gt;Assuming that you know which item you want to prevent the user from changing, all you have to do is register on the &lt;font face="Courier New, Courier, Monospace"&gt;ItemCheck &lt;/font&gt;event off either the CheckedListBox or the ListView, and write the following event handler:
&lt;p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;private &lt;/font&gt;&lt;font color="#0000ff"&gt;void &lt;/font&gt;checkedListBox1_ItemCheck(&lt;font color="#0000ff"&gt;object &lt;/font&gt;sender, System.Windows.Forms.ItemCheckEventArgs e)&lt;br&gt;{&lt;br&gt;    &lt;font color="#0000ff"&gt;if &lt;/font&gt;(e.Index == 0)&lt;br&gt;        e.NewValue = e.CurrentValue;&lt;br&gt;}&lt;/code&gt;
&lt;p&gt;One could add grayed-out coloring to the item, to visually notify the user that the item is disable, and of course, obviously you could keep a list of all indexes that are to be disabled this way.
&lt;p&gt;If you take a look at my previous post, and expand it to a CheckedListBox, you can just as easily keep the &lt;font face="Courier New, Courier, Monospace"&gt;Enabled &lt;/font&gt;state of the item in the obect itself, and use that in the &lt;font face="Courier New, Courier, Monospace"&gt;ItemCheck &lt;/font&gt;event.&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Prevent+changing+the+state+of+a+CheckBox&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!648.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!648.entry</guid><pubDate>Wed, 06 Sep 2006 12:05:09 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!648/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!648.entry#comment</wfw:comment><dcterms:modified>2006-09-06T12:08:52Z</dcterms:modified></item><item><title>Using ComboBox with objects</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!647.entry</link><description>&lt;div&gt;
&lt;p&gt;In most of the cases where you need to use a ComboBox, you need it only so the user will be able to choose between a couple of string values. In the majority of the cases, you’ll have a list of objects that you’ll want the user to choose from, and you’ll have to do something similar to this:
&lt;p&gt;&lt;code&gt;Hashtable idToItem = &lt;font color="#0000ff"&gt;new &lt;/font&gt;Hashtable();&lt;br&gt;&lt;font color="#0000ff"&gt;foreach &lt;/font&gt;(Item item &lt;font color="#0000ff"&gt;in &lt;/font&gt;listOfItems)&lt;br&gt;{&lt;br&gt;    &lt;font color="#0000ff"&gt;int &lt;/font&gt;index = comboBox.Add(item.DisplayName);&lt;br&gt;    idToItem[index] = item;&lt;br&gt;}&lt;/code&gt;
&lt;p&gt;We can now use the &lt;font face="Courier New, Courier, Monospace"&gt;SelectedIndex &lt;/font&gt;field of the ComboBox, in conjuction with the &lt;font face="Courier New, Courier, Monospace"&gt;Hashtable &lt;/font&gt;to retrieve the selected item.
&lt;p&gt;While the above code works perfectly, it does consume more memory, and takes more time than needed. And while you might say that both the time and memory wasted are negligible, try to use 10,000 items to a ComboBox, that go enjoy a cup of coffee while you wait for things to move around…
&lt;p&gt;There exist a simple and elegant way of doing the same thing. The &lt;font face="Courier New, Courier, Monospace"&gt;DisplayMember &lt;/font&gt;field of the ComboBox is mostly known in relation to binding the control to a data source. We are going to use it for something similar - our data sources will be the items themselves:
&lt;p&gt;&lt;code&gt;comboBox.DisplayMember = &amp;quot;DisplayName&amp;quot;;&lt;br&gt;&lt;font color="#0000ff"&gt;foreach &lt;/font&gt;(Item item &lt;font color="#0000ff"&gt;in &lt;/font&gt;listOfItems)&lt;br&gt;{&lt;br&gt;    comboBox.Add(item);&lt;br&gt;}&lt;/code&gt;
&lt;p&gt;Now we can just use the &lt;font face="Courier New, Courier, Monospace"&gt;SelectedItem &lt;/font&gt;field of the ComboBox, casting it to the correct type.&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Using+ComboBox+with+objects&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!647.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!647.entry</guid><pubDate>Wed, 06 Sep 2006 12:02:01 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!647/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!647.entry#comment</wfw:comment><dcterms:modified>2006-09-06T12:02:01Z</dcterms:modified></item></channel></rss>