How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »

 

Check if user has administartor rights

In numerous cases it is essential to know if the user has administrator rights or not. A good example for this would be when we want to decide if we want to write a value in HKEY_LOCAL_MACHINE which requires administrator rights or HKEY_CURRENT_USER which doesn’t.

The following method will return true if the application is running under administration rights or false if its not.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Create shortcut programmatically in C#

In cases where we need to create a shortcut for our application or for any other reason, the Windows Script Host Object Model library allows us to do just that.

In order to access the classes that will enable us to create shortcuts we need to add the Windows Script Host Object Model library as a reference to our project first.

  1. Right click on your project
  2. Click “Add Reference…”
  3. Select the “COM” tab on the left
  4. Search for Windows Script Host Object Model and add it as a reference

Windows Script Host Object Model add reference

After you successfully add the reference in your project you should be able to use the snippet bellow to create shortcuts as you please.

Create shortcut:

Usage:

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Start application at Windows startup with C#

The following snippet will allow you to add your application in the registry so it will launch when Windows start. Alternative you can use Environment.SpecialFolder.Startup to place a shortcut of your application in the startup folder which will have the same effect.

Note that this snippet will add an entry in HKEY_CURRENT_USER which means the program will only launch at startup for the user that is currently logged in when you run the code. If you want your program to run at startup for all users you will need to use HKEY_LOCAL_MACHINE instead but keep in mind that you will require administration rights in order to do that.

Register program to start with Windows:

Stop program from starting with Windows:

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Visual Studio 2012 Update 3

Microsoft released Visual Studio 2012 Update 3 (Visual Studio 2012.3) on June 26, 2013. This update introduces TFS build improvements as well as various bug fixes.

You can download the update from Microsoft’s download centre using the links below. Alternative you can use the links bellow to download the installation file that better suits your needs.

Note: Visual Studio 2012 Update 4 is now available. You can download it for free using the download links below.

Download Links

Web installation file: http://go.microsoft.com/?linkid=9821199
Offline installation file: http://go.microsoft.com/?linkid=9833082

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

How to draw Listbox items with alternative background colors

Some people find it easier to read large amount of data when the rows have an alternative background color instead of always the same. This is called Zebra Striping.

For this example we will look into implementing this technique for our ListBox control so it will look similar to this:
Listbox zebra striping

First we need to ensure that the ListBox.DrawMode property is set to DrawMode.OwnerDrawFixed. This can be accomplished by either changing the property in the properties window or by placing listBox1.DrawMode = DrawMode.OwnerDrawFixed; in your form’s constructor or any of the load events.

Then we need to handle the ListBox’s DrawItem event so we can change the colors as we like.

And we are done ! Feel free to modify the example to suit your needs.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone