Tag Archives: tutorial

Set placeholder text for textbox (cue text)

Setting placeholder text for your textboxes helps the users to identify better what kind of information it’s needed from them.

Instead of handling the focus enter and focus leave events in order to set and remove the placeholder text it is possible to use the Windows SendMessage function to send a EM_SETCUEBANNER message to our textbox to do the work for us.

This can be done with two easy steps. First we need to expose the Windows SendMessage function.

Then simply call the method with the handle of our textbox, EM_SETCUEBANNER’s value and the text we want to set.

The result will be a textbox with a placeholder text of our choice. The placeholder text will be automatically be removed when the textbox gains focus and will only reappear if the textbox loses focus and has no characters typed in it.

Cue text example

Create and extract .zip files in C#

Sadly there aren’t many flexible or efficient ways to create .zip files in .NET prior to .NET 4.5. Thankfully some people took the initiative and created some very easy to use libraries for creating/extracting and updating .zip files. My two all time favourite are DotNetZip and SharpZipLib.

For this example I will be using the DotNetZip library.

First you will need to download the library (.dll) either from http://dotnetzip.codeplex.com/ or from http://www.fluxbytes.com/?dl_name=DotNetZipLib_v1.9.1.8.rar. The file should contain quite a few libraries, so choose the one that suits your needs the most and add it as a reference in your project.

Limit the number of months displayed by WordPress archives widget

Locate and edit your themes functions.php file. This can either be done in the admin panel by navigating to

Appearance -> Editor -> Click on functions.php file

or by directly editing the file which you can usually find under

wp-content/themes/<theme name>/functions.php

After opening the file simply add the following lines in it.

Replace the number 10 with the number of months that you want to display and you are done!

List Windows active processes in C#

Since some people were interested on how to get all the Window processes, I decided to make this tutorial. How you tailor it to your needs is up to you.

We start off by referencing System.Management and adding the following on the top of our Form/Class:

Then we need to declare our main classes. In this case that would be ManagementClass and ManagementObjectCollection in order to help us loop through the active process. Note that this can also be done by Process.GetProcesses() but there is a limitation. Process.GetProcesses() can only see the same bit process as your .exe files. So using that mean we wont be able to see all the processes, hence why we are using the two classes I mentioned above instead.

After that we need to create our foreach loop which will help us get the information for each process we find and also a new listviewitem which we will be adding to our listview at the end of the loop so we can see the results.

For the sake of this tutorial we will only be concentrating in the process id/name/location and finally the description.