Windows Phone Developers

Thursday, July 26, 2012

C# .NET Images / Icons as Resources and Content

Build Action Resources vs Content in .NET / C# .NET Images / Icons as Resources and Content

Images can be added either as a Resource or Content Resource - This is default for Images / Icons Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.



Having Images as Content will reduce the Filesize. Having as a Resource appears to load the images faster .. it might be my perception. Please express your views on it Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

How to Add Icons to the Windows Phone Project (C#/.NET)

Windows Phone SDK comes with a list of Icons.

They are available in the following location

 Location of Icons in Visual Studio (Windows Phone Development):

On 32-bit operating systems: C:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Icons On 64-bit operating systems: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Icons

To add an icon to the project: Icons can be either created or added;

If you want to create a new Icon
 file use the following option

To add an existing icon, select from the list of Icons
 
Do some edits / updates if needed

Set the set the Build Action to Content.
            would
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

How to Enable ApplicationBar on Windows Phone (XAML)

How to enable Application Bar in Windows Phone Application using .NET The Application bar is available in the XAML file. It is commented by default. Remove the commented section and use the Application Bar in your App The ApplicationBar can be customized Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Sunday, May 6, 2012

Using Directive in C#, Create an alias in C#

Before you can use the classes in a given namespace in a C# program, you must add a using directive for that namespace to your C# source file. In some cases, you must also add a reference to the DLL that contains the namespace


The using directive has two uses:
· To allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

· To create an alias for a namespace or a type.

using Excel = Microsoft.Office.Interop.Excel

The using keyword is also used to create using statements, which help ensure that IDisposable objects such as files and fonts are handled correctly. See using Statement for more information.
The scope of a using directive is limited to the file in which it appears.
Create a using alias to make it easier to qualify an identifier to a namespace or type.

Big Statements like the following

oXL = new Microsoft.Office.Interop.Excel.application();

can be replaced with

using Excel = Microsoft.Office.Interop.Excel
oXL = new Excel.application();

Create a using directive to use the types in a namespace without having to specify the namespace. A using directive does not give you access to any namespaces that are nested in the namespace you specify.
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Calculating Time taken for an operation using VB.NET (in Milliseconds)

Calculate Processing Time for a Vb.NET Subroutine (accuracy to millisecond)


Not every project will have the luxury of having rational analyzer to check the process time for every subroutine/function. In those cases we can use the StopWatch to determine the time taken for a program

Imports System.Diagnostics

Sub Get_Accurate_ProcessTime()

Dim oWatch As New Stopwatch

oWatch.Start()

Process_database()

oWatch.Stop()

MsgBox("Total Time Taken for Database Operation := " & oWatch.ElapsedMilliseconds.ToString)


End Sub
A Stopwatch instance can measure elapsed time for one interval, or the total of elapsed time across multiple intervals. In a typical Stopwatch scenario, you call the Start method, then eventually call the Stop method, and then you check elapsed time using the Elapsed property.
A Stopwatch instance is either running or stopped; use IsRunning to determine the current state of a Stopwatch. Use Start to begin measuring elapsed time; use Stop to stop measuring elapsed time. Query the elapsed time value through the properties Elapsed, ElapsedMilliseconds, or ElapsedTicks. You can query the elapsed time properties while the instance is running or stopped. The elapsed time properties steadily increase while the Stopwatch is running; they remain constant when the instance is stopped.


By default, the elapsed time value of a Stopwatch instance equals the total of all measured time intervals. Each call to Start begins counting at the cumulative elapsed time; each call to Stop ends the current interval measurement and freezes the cumulative elapsed time value. Use the Reset method to clear the cumulative elapsed time in an existing Stopwatch instance.
The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.


The Stopwatch class assists the manipulation of timing-related performance counters within managed code. Specifically, the Frequency field and GetTimestamp method can be used in place of the unmanaged Win32 APIs QueryPerformanceFrequency and QueryPerformanceCounter.
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Regular Expression to Check Zip Code

Regular Expression to Match Zip Code

Imports System.Text.RegularExpressions
Function IsValidZip(ByVal sZipCode As String)
Return Regex.IsMatch(sZipCode, "^\d{5}(\-\d{4})?$")
End Function
The above will check for U.S . Zip codes like 55001-2434. 94941-3232 etc
To Check Indian Zip codes use
Imports System.Text.RegularExpressions
Function IsValidZip(ByVal sZipCode As String)
Return Regex.IsMatch(sZipCode, "^\d{6}$")
End Function
Matches 600040, 400123 etc
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Check if Path is Absolute or Relative Path using C# (.NET)


IsPathRooted method of Path class returns a value indicating whether the specified path string contains absolute or relative path information.

if (Path.IsPathRooted(@"c:\temp\") == true)

{

Console.WriteLine("Path is absolute");

}

else

{

Console.WriteLine("Path is relative");

}

How to find absolute path using C# (.NET), How to find relative path using C# (.NET), C# (.NET) Path Class, C# (.NET) IsPathRooted method
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon