Sunday, June 29, 2008

Using Brushes with Semi-Transparent Color

Filling a Rectangle, Ellipse, Shape, etc. with a semi-transparent fill is done by using a SolidBrush with a Alpha value somewhere between solid and transparent.

C#:

Color col = Color.FromArgb(75, 100, 100, 100);
SolidBrush b = new SolidBrush(col);
g.FillRectangle(b, 0, 0, this.Width - 1, this.Height - 1);


VB.NET:

Dim col As Color = Color.FromArgb(75, 100, 100, 100)
Dim b As New SolidBrush(col)
g.FillRectangle(b, 0, 0, Me.Width - 1, Me.Height - 1)




For better examples, go to this link:

http://www.java2s.com/Code/CSharp/2D-Graphics/Filledwiththesemitransparentandtransparentcolor.htm

Wednesday, June 18, 2008

Disappearing Controls in the Left SplitContainer Panel when using Large Fonts

I have been experiencing a strange problem that I have finally confirmed as a bug in the .NET Framework 2.0. If you are using a SplitContainter and place controls in your Left panel, then if you anchor those controls to the Right or the Bottom, they will disappear when you run the app on a machine that is using Large Fonts. My controls happen to all be in a group box, but I don't think that matters. The controls disappear because the anchor is setting the height and/or width to 0 and they are not visible. If you can drag the size wide or tall enough, the controls will start to appear, but they scaling is off and the anchor is not working correctly. If using Small Fonts, this problem does not exists.

I found a few other people with the same problem, but no solutions. I found one suggestion to do a Refresh on the Splitter move event, but this did not help me. My solution has been to adjust the size of the controls in the left panel myself and not rely on the anchor. Please post a comment if you have a better solution to this problem.

Saturday, June 14, 2008

Setting BackColor to System Colors (like "Control")

It took a little searching to find out how to set the BackColor or ForeColor property of a control to the predefined colors you gets in the Visual Studio Properties window for BackColor's popup color setting on the System tab. For example, I want to set to the BackColor to the "Control" color.

control.BackColor = Color.FromKnownColor(KnownColor.Control)


I found this on:

http://bytes.com/forum/thread654472.html

Thursday, June 12, 2008

TechEd 2008 in Orlando



The TechEd 2008 Deveveloper’s Conference was in Orlando last week. I have always attended MEDC (Mobile and Embedded Developer’s Conference) before, but it has now been merged into TechEd. I believe that I prefer the more focused content of MEDC, but if my only way to get this information is to go to TechEd, then it is not too bad of an alternative. However, there were only 11 Windows Mobile session at TechEd 2008.

There is always a flavor to a Microsoft conference. I don’t know if this is directed by the powers that be or simply a natural alignment to the new features they are providing (or a combination of both). This year, the flavor definitely tastes of LINQ (Language Integrated Query). LINQ is undeniably an interesting concept that directly integrates SQL-like statement into the language syntax of any .NET language (VB.NET, C#, etc.). What makes this new feature somewhat interesting is that the SQL statements can be applied to data in arrays, enumerable objects, XML, and databases. So, the SQL way of querying a database can now be directly applied to data in your application, not just databases.

It also appears that most of the new language features we get from Visual Studio 2008 are directly related to LINQ: Anonymous Types, Extension Methods, Lambda Expressions, Implicitly typed locals, and Object Initializers. All of these new features were added just to support LINQ. One session on the Visual Studio 2008 IDE revealed that there wasn’t much added to the IDE because all of the developers were working on LINQ. On the downside, while LINQ does run on Windows Mobile, it will only work with your application data and does not work with SQL CE. There are a lot of things in the Compact Framework I would have rather had than a partially implemented version of LINQ.

While just about every session had to work LINQ in somehow, there were a couple of other technologies that were shown off. The Windows Presentation Manager (WPF) has developed a good deal since last year and can really produce some spectacular looking demos. The new support in Visual Studio 2008 for WPF is nice, but really seems to be early in its development. All of the WPF sessions seem to highlight a few points: it has great potential, it’s not here yet, and you will need a graphic designer to properly use it. A common phrase I heard in the session is “I’m not a graphic designer, so my WPF doesn’t look very good.” Nevertheless, I still found the Technology compelling enough to pursue. As an aside, Silverlight, which is an offshoot of WPF, came across as a very immature technology. Maybe it will mature quickly.

The Window Communication Foundation (WCF) was also a popular topic. It is just the extension of Web Services to what it probably should have been in the first place.

The Windows Workflow Foundation (WF, because WWF was already taken), was new to me and looks really interesting. An oversimplified description of it would be a project type in Visual Studio that lets you create a flow chart or diagram of your business logic and then can add the code behind the items in the diagram. The WF demos were compelling, but I have to question how well it really works in the real world. The demos used very simplistic logic. How well WF scales to a real application would be interesting to know. I think time will tell on this technology. It will become really popular or just disappear.
Another interesting thing about TechEd 2008 is what they didn’t talk about. Normally, these conferences are all using beta versions of something that hasn’t been released. I went to MEDC two years in a row and all they talked about was Whidbey (VS2005). Then it was all about Orcas (VS2008). With the exception of running VS2008 service pack 1 betas and a Silverlight beta, everyone was pretty content with the released software (quite a change from previous conferences). Does this mean there isn’t anything new in the queue or they are just taking a little longer to ramp up to the new stuff.

All and all, I was pretty pleased with the conference. Visual Studio 2008 looks good enough now to upgrade to (although I may wait until SP1 until I start upgrading all of my projects). Check out the full video and text of Bill Gates’ key: http://www.microsoft.com/presspass/exec/billg/speeches/2008/06-03teched.mspx

Getting Selection and Arrow keys to behave right with a ListBox in the.NET Compact Framework

I had a form in a Window Mobile application that contains a Label and a ListBox. I wanted the ListBox to behave according to the Windows Mobile UI guidelines where you click on an item with the stylus and it is automatically selected. I used the SelectedIndexChanged event to implement this behavior and it worked fine when an item was selected with the stylus. However, with all of the different kinds of devices, many of them have partial or even full keyboards and at the very least they have a joypad or equivalent, my users were wanting to use the arrow keys to navigate to a specific item in the list and then press the enter button (never using the stylus). Unfortunately, the SelectedIndexChanged event is fired anytime the ListBox’s selected item is change (by stylus or keys) and since using the arrow keys usually requires scrolling through several items before getting to the item you want, the next item in the list is always selected (be it the one you want or not). I could not find a way in the .NET Compact Framework to get the ListBox to work like I wanted.

My solution was to replace the ListBox with a ListView. Change the View property to Details and change the Activation property to OneClick. Then use the ItemActivate event provided by the ListView instead of the SelectedIndexChanged event. You also have to add at least one Column to the ListView, and you can optionally set HeaderStyle to None to get rid of the column header and make the ListView look just like a ListBox.