Thursday, May 28, 2009

Signature panel

We can create a signature panel using Visual Studio and MouseMove, MouseDown and MouseUp events of any control.
// Code ***********************
Bitmap bitimage;
Graphics graphSignature;

Point pnt;
Point prepnt;
Graphics gSignature;
bool mousedownclicked = false;
public Form1()
{
InitializeComponent();

bitimage = new Bitmap(this.Width, this.Height);
graphSignature = Graphics.FromImage(bitimage);
gSignature = this.CreateGraphics();
// create a white background
gSignature.Clear(Color.White);
graphSignature.Clear(Color.White);

}
private void MouseMoveForm(object sender, MouseEventArgs e){
gSignature.DrawLine(new Pen(Color.Red, 5.0F), prepnt, new Point(e.X, e.Y));// For display
graphSignature.DrawLine(new Pen(Color.Red, 5.0F), prepnt, new Point(e.X, e.Y));// For saving
prepnt.X = e.X;
prepnt.Y = e.Y;
}
private void MouseDownForm(object sender, MouseEventArgs e)
{
mousedownclicked = true;

pnt.X = e.X;
pnt.Y = e.Y;

prepnt.X = e.X;
prepnt.Y = e.Y;
}
private void MouseUpForm(object sender, MouseEventArgs e)
{
mousedownclicked = false;
}
//Code END ******************

-Abinaw

Tuesday, May 19, 2009

How to find out your location on a laptop?

We can use RIL_Initialize, RIL_GetCellTowerInfo, RIL_GetCellTowerInfo, RIL_Hangup, RIL_Deinitialize of the windows CE to find out our own location in the longitude and latitude forms. This information then can be used with Google MAP APIs to get the exect graphical view with the street and city.
-abhinaw

Friday, May 15, 2009

Google Static Map API

Google released APIs for static map sometimes ago.
see this url:http://code.google.com/apis/maps/documentation/staticmaps/#Latlons
I noticed that the the example given in the "A Quick Example " section does not have the correct url.If you use the url given in the example then you will not get the markers in the map.
The correct url is:
http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile\&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY&sensor=false

The difference is the "\" before &key. remove that slash(/) and you will get the correct url which will show markers in proper color.

-Abhinaw


Monday, May 11, 2009

conversion from VB6 to Visual Studio .NET 2008

.NET has much more power than VB6 and this provides a very good reason to convert the existing VB6 projects to VS 2008 .NET .
Start with opening Visual Studio 2008 IDE.
open the existing VB6 vbp file. The converiosn wizard will guide you through the steps to convert all the VB6 files to the .NET files. It will also create a report and a back up folder in case you want to revert back to the old version.

If Microsoft.Sqlserver.MSXML6 was used in VB6 code then it will give compilation error in the .NET. you can replace it with System.NET namespace and use the HttpWebRequest class.
Dim oHTTP As System.Net.HttpWebRequest ( this is a replacement for Dim oHTTP As Microsoft.SqlServer.MSXML6.ServerXMLHTTP in the Vb6 code).

Morr posts will follow on this article.
Thanks
-Abhinaw

Friday, May 8, 2009

TraceListeners in .NET

Trace object in .NET has a default trace listener and out put to this default trace listener can be viewed by using debugview utility from Microsoft ( sysinternals). It is also possible to direct the out put from Trace object to any other listener. Listener means any text file or Console or even log where we can write some text messages.
//Following line will create a text file ( MyLogs.txt ) in the same directory where the application //is running.
private static System.Diagnostics.TextWriterTraceListener TL = new TextWriterTraceListener(Environment.CurrentDirectory + "\\MyLogs.txt");
//Add this listener to the Trace object
Trace.Listeners.Add(TL);
//Write information to the txt file
Trace.WriteLine("Some Informational Message here");

This is a powerful technique to write logs to a specified txt file. The TL switch can be used to set the Trace level and also to enable or disable the trace.
- Abhinaw

Wednesday, May 6, 2009

Microsoft F#

F# is a new language by Microsoft.
F# is a functional programming language built on .NET framework. It uses WPF and WCF libraries and provides a very easy yet powerful interface for rapid development.
You can download F# latest release (v1.9.6.0) at:
http://www.microsoft.com/downloads/details.aspx?FamilyID=61ad6924-93ad-48dc-8c67-60f7e7803d3c&displaylang=en

#light and let are the two very important key words of F# language.
There is a very informative introductory video on Microsoft website.
check the video here
http://channel9.msdn.com/pdc2008/TL11/

I will post more about F# as I develop projects based on F#.

-Abinaw

Tuesday, May 5, 2009

Displaying Foms in Panels in Visual Studio .net

Visual studio comes with a very useful control named as splittercontrol.
This can be used to create different sections in the Winform application just like a Microsoft outlook. These sections can be configured at run time and a user can re size the panels.
******* Code hints ***************
//add a winform frm1.cs to the project
//declare a static SplitterPanel as shown:

public static SplitterPanel P1 = null;
// Add the following function.
public static void ShowWithinPanel(Form frm)
{
// frm is the instance of a form which is included in the same project and
// you want this form to appear insie the panel.

frm.TopLevel = false;// top level controls can not be added to the split container.
P2.Controls.Add(frm);
P2.Controls[frm.Name].Dock = DockStyle.Fill; // It will fill the panel
P2.Controls[frm.Name].Show();
}

- Abhinaw

Monday, May 4, 2009

Trace view /Debug View in .NET

Microsoft introduced two switches in .NET 2.0 and higher.
These two switches are BooleanSwitch and TraceSwitch
Usage in the code is as follows:
private static BooleanSwitch bw = new BooleanSwitch("EnableTrace", "Boolean Switch for logging");
private static TraceSwitch tw = new TraceSwitch("TraceSwitchLevel", "Trace Switch for Level of Logs");

Also define these switches in the .config file for the application as follows:

"-system.diagnostics-
-switches-
-!-- This switch controls data messages. In order to receive data trace messages, change value="0" to value="1" --
-add name="EnableTrace" value="0">
-!-- This switch controls general messages. In order to receive general trace messages change the value to the appropriate level. Disable Trace = "0" Error = "1" Errors and Warnings = "2" More detailed error information = "3" Verbose trace information = "4" --
-add name="TraceSwitchLevel" value="4"-
-/add>
-/add>"

Note that the name of the switches used in the config files and in the code are same. This is important. Do not use a different names in config and code files.
TraceSwitch are incremental. If you specify a values of 3 then it will include 2 and 1 also and so on.

You can write log in a txt file or if you do not specify any file then all the logs can be seen in the DebugView utility provided by microsoft. You can download it from http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

-Abinaw

Friday, May 1, 2009

Static Logging class for rich log information

public static class Logging
{
public static void Log(string strLogMsg)
{
System.IO.StreamWriter w = null;
try
{
StackFrame frame = new StackFrame(1, true);// 1 = it will skip the first frame . first frame is the curent frame. true will give the file name
System.Reflection.MethodBase method = frame.GetMethod();
string strLog = method.Name + ":" + method.DeclaringType.FullName + ":" + frame.GetFileLineNumber();
System.IO.FileInfo finfo = new System.IO.FileInfo(Environment.CurrentDirectory + "\\Logfile.log");
w = finfo.AppendText();
w.Write("[" + DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString() + "]");
w.Write("[" + Environment.UserName + "]");
w.Write("[" + strLog + "]");
w.WriteLine(strLogMsg);
w.Flush();
w.Close();
}
catch(Exception ex)
{
w.Close();
}
}
}

The results of this log file will look like this:
[4/30/2009 4:24:33 PM:980][userName][FucntionName:FileName:LineNumber]
This is very useful to trouble shoot and investigate the root cause of the error.

-Abhinaw