Monday, August 27, 2007

Drawing a filled rectangle on a windows form

This is quite straight-forward. Override the OnPaint() method with the following code:

And it's done. A filled rectangle will be painted at the top of the form.

The code is in the overridden OnPaint() method so that each time the form is resized/obscurred by another form, the content will be re-painted automatically. Also, it is a good practice to call the Dispose methods of objects that consume system resources heavily (e.g. Brush and Graphics objects).

Thursday, August 2, 2007

Cradle a device emulator and access the internet

Visual Studio 2005 is installed.
Microsoft ActiveSync 4.0 or later is installed.
An internet connection is available.

Often a device emulator attempts to connect to the internet via the pc and the following message is encountered: Cannot Connect - Unable to connect: You have no modem entries created, and no network card present.

Here is a simple walkthrough, with some tips, describing how an emulator can be launched from Visual Studio, cradle it via ActiveSync and access a web page on the internet (obviously, provided that the PC is connected to the net).

Step 1: Launch an emulator (say Pocket PC 2003 SE Emulator)

a) Start Visual Studio 2005.

b) Go to the Device Emulator Manager (Tools -> Device Emulator Manager)
A list of available emulators will be displayed in the Device Emulator Manager window.

c) To start the emulator, right click PC 2003 SE Emulator and select Connect.
The Emulator will start.

Step 2: Attempt to browse a web page via Internet Explorer

a) Launch Internet Explorer (Start -> Internet Explorer) from the Device Emulator and your web page url, say enter

The error message will be displayed: Cannot Connect - Unable to connect: You have no modem entries created, and no network card present.

Step 3: Cradle the emulator

The emulator must be cradled (as it would have been the case for a physical device) and connect it to the PC via ActiveSync.

a) To cradle the emulator, go to the Device Emulator Manager in Visual Studio (Tools -> Device Emulator Manager).

b) Right click on the connected emulator, and select Cradle.
The emulator will now be cradled and connected to ActiveSync.

Step 4: Access the web page (repeat step 3)
The Internet Explorer on the emulator will successfully browse to the web page.

Great, isn't it?