Thursday, December 17, 2009

K-MUG Session on 19th Saturday at Technopark, Trivandrum





next K-MUG User group session on 19th Saturday. More details can be located under event page of Kerala Microsoft Users Group (K-MUG) web site.

Wednesday, June 10, 2009

How to Scale your entire App and its Elements to your Browsers Size

Wow, Today I found the answer of the question "How to Scale your entire App and its Elements to your Browsers Size?" And the answer of the question "How to Scale your entire App and its Elements to your Browsers Size?" And the answer provided to me is by the silverlight 2.0. I always wonder that how can i scale my application to different browser sizes... and to different screen resolutions I found some PHP sites which were scalable according to the browser size but was unable to handle the same in my ASP.net applications... I have Hear-ed a lot about the silverlight and its applications but never give a thought to it and now finally when my client needs the scalable sites then i have no other option left with me i have to search it and thought to go ahead with silverlight and today only i get all the essentials for the silverlight and started to find the solution and to my wonders i found the solution so simple and easy... Here I would like to share it with you all...

Saturday, April 18, 2009

Fast clean way to check if an array contains particular element in C# 3.0

A good to know that really fast and the most elegant way to check if an array contains particular element in C# 3.0 seems to be using Contains() extension method.

using System;
using System.Diagnostics;
using System.Linq;
namespace Test
{
class Program
{
static void Main(string[] args)
{
int[] data = new int[10000000];

Random rand = new Random();
for (int i=0; i{
data[i] = rand.Next();
}

int value = data[data.Length/2];
ContainsViaForEachLoop(data, value);
ContainsViaForLoop(data, value);
ContainsViaContainsExtMethod(data, value);
ContainsViaAnyExtMethod(data, value);
Stopwatch watch = new Stopwatch();
watch.Start();
if (ContainsViaForEachLoop(data, value))
{
watch.Stop();
Console.WriteLine("foreach loop search:\t\t{0} ms",
watch.ElapsedMilliseconds);
}
watch.Reset();
watch.Start();
if (ContainsViaForLoop(data, value))
{
watch.Stop();
Console.WriteLine("for loop search:\t\t{0} ms",
watch.ElapsedMilliseconds);
}
watch.Reset();
watch.Start();
if (ContainsViaContainsExtMethod(data, value))
{
watch.Stop();
Console.WriteLine("Contains() method search:\t{0} ms",
watch.ElapsedMilliseconds);
}
watch.Reset();
watch.Start();
if (ContainsViaAnyExtMethod(data, value))
{
watch.Stop();
Console.WriteLine("Any() method search:\t\t{0} ms",
watch.ElapsedMilliseconds);
}
}
public static bool ContainsViaForEachLoop(int[] data, int value)
{
foreach (int i in data)
{
if (i == value)
{
return true;
}
}
return false;
}
public static bool ContainsViaForLoop(int[] data, int value)
{
for (int i=0; i{
if (data[i] == value)
{
return true;
}
}
return false;
}
public static bool ContainsViaContainsExtMethod(int[] data, int value)
{
return data.Contains(value);
}
public static bool ContainsViaAnyExtMethod(int[] data, int value)
{
return data.Any(i => i == value);
}
}
}

Accessing the properties of the event sender

I was Having two Controls in the Sender one dropdown list and other is a Radio Button List
the Access the object Sender

if (sender is DropDownList)
hiddenSelectedOptionID.Value = ddlOptions.SelectedValue;
if (sender is RadioButtonList)
hiddenSelectedOptionID.Value = rblTypes.SelectedValue;

Screenshot in 2 Clicks using .NET

Step 1: Fire up Visual Studio 2008 and Create a new Windows Application.
Step 2: From the toolbox, add a ‘ContextMenuStrip’ and a ‘NotifyIcon’ to the form.
Step 3: Choose an icon for the’ NotifyIcon’ using the Icon property. Change the ‘ContextMenuStrip’ property of the NotifyIcon to ‘contextMenuStrip1’ (which we added in Step 2)
Step 4: Add a new menu item to ContextMenuStrip1 control named “Grab Screenshot” as shown in the screen below:














Now double click this MenuItem and add the following code to its click event:
C#
private void grabScreenShotToolStripMenuItem_Click(object sender, EventArgs e)
{
Bitmap bmpSS = null;
Graphics gfxSS = null;

try
{
bmpSS = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);

gfxSS = Graphics.FromImage(bmpSS);

gfxSS.CopyFromScreen(
Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);

SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Filter = "JPeg Image*.jpg";
saveDialog.Title = "Save Image as";
saveDialog.ShowDialog();
if (saveDialog.FileName != string.Empty)
bmpSS.Save(saveDialog.FileName, ImageFormat.Jpeg);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}



Note: Make sure you import System.Drawing and System.Drawing.Imaging namespaces.
In the code above, we create a new Bitmap which is equal to the width and height of the primary screen and then we create a new graphics using the Bitmap. We then use the CopyFromScreen() to capture the screen. Once this step is done, we create an object of SaveFileDialog and display it to the user to choose the location and save the file as an .jpeg image.
Step 5: Add the following code to the Form load event which will hide the form and remove it from taskbar.
C#
private void Form1_Load(object sender, EventArgs e)
{
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
this.Hide();
}



Now run the program and right click the Icon that appears in your status bar. Click on the ‘Grab ScreenShot’ and save the screenshot to the desired location.

The next time you want a screenshot, remember it’s just two clicks away!
The entire source code of this article can be downloaded from here.

Tuesday, April 14, 2009

toolbar powered by Conduit