lamp

April 2009 - Posts

Enum Parser
30 April 09 05:46 PM | Frederick.Chapleau | with no comments

When having only the value from an enum, it is possible to get the enum value.

Try using Enum.IsDefined(typeof(enum), string) and Enum.Pars(typof(enum), string)

-f.

Filed under:
Icons… for free!
29 April 09 08:38 PM | Frederick.Chapleau | 1 comment(s)

What to improve your software by adding icons? There is many websites selling them, but there is not many ones with free icon, that you can use legally.

The most popular one is the Fam Fam Fam collection of icons, and I recently found FreeFavicon that is a great collection too.

-f.

Filed under:
SNK, Only one is needed
28 April 09 09:55 PM | Frederick.Chapleau | with no comments

When you want to digitally sign your application using a Strong Name, it is the combination of the SNK, the Assembly name and the public key token that make it unique.

So, you can sign all your assembly using the same SNK, and use a Company wide signature so that you can recognize or validate the signature of your applications.

Also, if you want to keep the SNK private, there is a possibility to delay sign your assemblies.

-f.

Ref:

Sign an Assembly with a Strong Name

Delay sign an assembly

Filed under:
Application Versioning
27 April 09 11:43 PM | Frederick.Chapleau | with no comments

Did you know that you can simply get the version of the application by going to Application.ProductVersion… ? And you can also get the Assembly version by using reflection, assemblyobject.GetName().Version .

-f.

Filed under:
Use of Property Accessor
26 April 09 02:02 PM | Frederick.Chapleau | with no comments

(Almost) everybody is using them, but did you even think why?

There is many reasons why using them. The main one, is to control who, when and how caller are accessing the value. You can also validate data before setting it, or expose data, loaded on demand.

More information can be found on MSDN.

-f.

Filed under:
Invoking when multi-threading
25 April 09 01:15 PM | Frederick.Chapleau | with no comments

Multi-threading is the new way to develop, if you want to fully use the computer power. But (there is always a but), if you want to safely update the UI, you must invoke the method, instead of just calling it, when you are not on the Form’s thread.

There is multiple way to do that, and each of them are more or less complex. There is a good tutorial on Code Project, take it a look when it’s time to multithread you app… and remember the “InvokeRequired” attribute of the form/control. Also remember that CheckForIllegalCrossThreadCalls is only working in Debug mode!

-f.

Filed under:
Implementing IComparable
24 April 09 11:54 AM | Frederick.Chapleau | with no comments

Often, it is useful to compare object instances between them. The comparison is useful for many things and the most basic one is to sort them.

.NET provide a mechanism to handle it, that is the implementation of IComparable. In .NET 2.0, there is an generic implementation to type the comparison and compare only entities that you can handle. Take a Look a IComparable<>.

Also, you can take a look an article Implementing an Extension to Sort ControlCollection in .NET 3.5 to view an example of what you can to when using this kind of generic interface.

-f.

Filed under:
Generic Event Handler
23 April 09 09:14 AM | Frederick.Chapleau | with no comments

Did you know that since .NET 2.0, a generic event handler exists?

In the System root, there is a EventHandler<eventArg>… So, it’s no longer needed to create the typed Handler, just create your EventArgs, and Declare your event!

-f.

Filed under:
Minimize it to the Tray
22 April 09 01:14 PM | Frederick.Chapleau | 2 comment(s)

When integrating a Tray Icon to your application, it is a good idea to add a Minimize to Tray option as Outlook.

This can be done using a simple line that detect form resize, and when the WindowState is Minimized, call the Hide() function on the form, and on the doubleclick event of the tray icon, call the Show() function, and change the WindowState to Normal.

-f.

Filed under:
Using region instead of single line comments
18 April 09 02:15 PM | Frederick.Chapleau | with no comments

Documenting code can be very long, and keeping the comments in-sync with the code is even harder.

A solution for that is to use region, instead of comments. This way of documenting has two purpose comment the code, and scope the comment. And also, this force a user to keep the region’s name/comment in-sync, because it is delimiting a part of the code itself.

-f.

Filed under: