How to change Visual Studio 2010 Color Palette

By Mohammad Mahdi Ramezanpour at April 04, 2010 04:51
Filed Under: .NET General

I know a lot of developers who can’t stand Visual Studio color scheme and they need to change the color of it. As you know, Microsoft changed VS’s color scheme to a much better but some of the developers that I know can’t stand it either.

Visual Studio 2010 Color Scheme

After some days of research, I found an extension for Visual Studio 2010 (RC is included) which changes the VS’s color scheme to whatever you want. Here’s an example:

Themed Visual Studio

After you install the extension, a “Theme” menu will be added to your VS IDE:

Theme Menu 

As it’s obvious, you can select from the list of built-in themes or, you can customize a new theme for yourself.

You can download this extension by Click Here.

Matthew Johnson – Developer, Visual Studio Platform, described this extension in details so you can check it out here: http://blogs.msdn.com/visualstudio/archive/2010/01/04/changing-visual-studio-s-color-palette.aspx

Hope it helps.

String.IsNullOrWhiteSpace in .NET Framework 4

By Mohammad Mahdi Ramezanpour at March 03, 2010 03:13
Filed Under: .NET General

Microsoft .NET New Logo As you know, String class in .NET Framework contains lots of methods and properties that related to strings. One of the popular methods that we had in previous versions of .NET (3.5, 2.0, etc.) was String.IsNullOrEmpty that indicates whether a String variable contains a string or it’s Null (Nothing in VB). I’m using this method a lot of time in my project it becomes one of my favorite methods in .NET.

But what if you want to check if a String variable is Null or is contains White spaces! It’s something that I wanted to explain in this post.

In Visual Studio 2010, Microsoft introduced a new method in the String class. The method is String.IsNullOrWhiteSpace that Indicates whether a specified string is null reference (Nothing in Visual Basic), empty, or consists only of white-space characters.

How it works:

The following code shows you how to use String.IsNullOrWhiteSpace method:

using System;

public class Example
{
public static void Main()
{
string[] values = { null, String.Empty, "ABCDE",
new String(' ', 20), " \t ",
new String('\u2000', 10) };
foreach (string value in values)
Console.WriteLine(String.IsNullOrWhiteSpace(value));
}
}
// The example displays the following output:
// True
// True
// False
// True
// True
// True

For more information please visit: http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace%28VS.100%29.aspx

Hope it helps.

How to change Windows Desktop Wallpaper using C# and Windows APIs

By Mohammad Mahdi Ramezanpour at February 23, 2010 04:05
Filed Under: .NET General

It’s about a week that I’m working on an advertising application which manages customer’s advertising programs. One of the cool features that my customer requested was to change user’s desktop wallpaper into a specific photo or add some advertising notes to the current wallpaper.

So I started developing this application and faced something: “How to programmatically change Windows Desktop Wallpaper?

As you know, to change anything in Windows, you have to make use of Windows APIs. This one is the same. In order to change anything in Control Panel, There is an API function, named “SystemParametersInfo” :

The SystemParametersInfo function retrieves or sets the value of one of the system-wide parameters. This function can also update the user profile while setting a parameter.

How it works:

First of all you need to import System.Runtime.InteropServices namespace. This namespace enables you to import your favorite Windows API function library.

Note that SystemParametersInfo function is in User32.dll library.

To import a Windows API library in C#, it’s necessary to use “DLLImport” attribute:

[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction,
int uParam,
string lpvParam,
int fuWinIni);
Now you have the function, so you have to use it somewhere:
 
string path = @"C:\Users\Public\Pictures\Sample Pictures\Desert.bmp";
const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;

SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,
path,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);

Note that, the file you specify to be the wallpaper must be in Bitmap format. If you have JPEG, PNG, etc. files, you have to convert it to Bitmap, save it in a temp folder and then set it as Windows wallpaper.


Develop your .NET 3.5 or older applications on Visual Studio 2010 IDE

By Mohammad Mahdi Ramezanpour at January 05, 2010 06:44
Filed Under: .NET General

It’s about two month that I’m working on the new version of Visual Studio 2010 and .NET 4. The new version of .NET has some cool features that you can use in order to develop your applications much better but what I’m going to write about today is the way that you can use in order to develop you .NET 3.5 or older on the Visual Studio IDE. Upgrading to the new version of .NET is sort of risky because not many web hosts support .NET 4 and the main reason is, .NET 4 is still beta! But it doesn’t mean that you cannot use the new IDE! You can easily set the “Target Framework” to 3.5 or even 2 if you’re not going to upgrade to .NET 4. In order to do this, you can follow these steps:

  • Open your project in the Visual Studio 2010 by click File -> Open Project. When you select your specified solution, the following window will be showing up:
    VS2010_UpgradeWizard
  • Click Finish and now you can see your project’s files in the VS2010’s Solution Explorer.
  • Right-Click on the solution and select properties.
  • In properties window, select Application tab and you can see the Target Framework DropDownList:
    Visual Studio 2010 Target Framework
  • As you can see in the picture above, you can select any framework that you’ve installed on your machine or you can install additional frameworks by select “Install other Frameworks” item.

Now you can develop your .NET 3.5 or older versions on the VS2010 IDE. By the way, in the next post, I’m going to write about Visual Studio IDE.

Hope it helps.

Useful Regular Expressions

By Mohammad Mahdi Ramezanpour at March 11, 2009 19:49
Filed Under: .NET General

Today I’ve developed a class library which manages some text validations and named it “RegularExpressions.cs”. It was an easy-to-develop class but, some of the expressions were good. It uses the System.Text.RegularExpressions.Regex class in order to check for the validations. In this post, I’m going to name some of the most useful regular expressions, you may need in your usual developments.

Numeric:
Pattern: ^[-+]?\d*\.?\d*$
Matches: 123 | +3.14159 | -3.14159
Non-Matches: abc | 3.4.5 | $99.95

Email Address:
Pattern: ^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
Matches: asmith@mactec.com | foo12@foo.edu | bob.smith@foo.tv
Non-Matches: joe | @foo.com | a@a

URL:
Pattern: ^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$
Matched: http://www.blah.com/~joe | ftp://ftp.blah.co.uk:2828/blah%20blah.gif | https://blah.gov/blah-blah.as
Non-Matches: www.blah.com | http://www.blah"blah.com/I have spaces! | ftp://blah_underscore/[nope]

For complete list of useful regular expression you can check out: http://www.regexlib.com/

Currently Reading

Quote of the day

Send Persian SMS