Click here to Skip to main content
14,365,424 members

.NET CF and Google APIs

Rate this:
3.22 (29 votes)
Please Sign up or sign in to vote.
3.22 (29 votes)
24 May 2004CPOL
Sample application to access Google APIs from a .NET Compact Framework application

Sample Image - dotNETCF_Google.png


This article is primarily for trying to win a Pocket PC! Originally I submitted an article to MSDN Canada for the Between the Lines contest and won for the Month of April. That article was titled "Tips & Tricks & Best Practices with Multithreading and .NET CF" and focused on accessing the Google API using the Compact Framework and multithreading an application as to not lock up the user interface. I have made a few updates to the original application and this article will focus on three new items:

  1. Supporting Landscape and Portrait mode for Square(240x240) or Rectangular(240x320) for Windows Mobile 2003 SE
  2. Creating a "floating" window for the settings and about screen


The source code provided is a continuation of my original code developed for the "Between the Lines" contest held by MSDN Canada and primarily dealt with multithreading a Compact Framework application. To read that article here. Also of note, the Google API for .NET CF does use Smart Device Framework (SDF). These files are included in the Demo Project but are not included in the Source project. To download these files go to The main SDF libraries that are used are OpenNETCF.Windows.Forms.HTMLViewer to show the Google Search Results and OpenNETCF.Configuration.ConfigurationSettings. The library is a great addition to anyone's development tools currently developing for the Compact Framework. If you don't currently use it I recommend you download the SDF at and start using it. The SDF adds a lot of functionality that is not included in V1 of the Compact Framework and best of all the source is included!!

To run the code you will have to register at and get a key. Once you get this key you must enter it in the settings within the application and then you will be able to search. The Google API is in beta and I don't know if they will charge a search fee in the future but I am sure they will let us know.

Portrait or Landscape

The first item I will go through is supporting landscape and portrait mode for Windows Mobile 2003 SE. To take advantage of the different screen layouts you must layout all your controls through code and handle the Resize event of the form. If this is not done scrollbars will be automatically added to your form if any controls go out of the screen bounds.


Figure 1: Portrait Mode


Figure 2: Landscape Mode

The following example shows how the sample application adjusts the controls depending on the screen size.

// Wiring up the event to handle resize


this.Resize+=new EventHandler(Form1_Resize);
// Event handler for Resize
private void Form1_Resize(object sender, EventArgs e) 
//Adjust the controls approprialty
private void ResizeForm() 
   //Setup the buttons for the screen 
   this.btnSearch.Left = this.Width - this.btnSearch.Width - 1; 
   //Resize the buttons 
   this.btnNext.Left = this.Width-this.btnNext.Width - 1; 
   this.btnNext.Top = this.Height-this.btnNext.Height-1; 
   this.btnPrevious.Top = this.btnNext.Top;  
   this.btnPrevious.Left = 1;
   this.lblCount.Top = this.btnNext.Top;
   //resize the html screen 
   this.htmlGoogleResults.Left = 1; 
   this.htmlGoogleResults.Top = this.btnSearch.Top + this.btnSearch.Height + 1; 
   this.htmlGoogleResults.Height = this.Height- htmlGoogleResults.Top - 
   this.htmlGoogleResults.Width = this.Width -2; 

   //Resize the search bar 
   this.textBox1.Width = this.Width-this.btnSearch.Width -3; 

   //Resize the result lable 
   this.lblCount.Left = btnPrevious.Left+btnPrevious.Width + 2; 
   this.lblCount.Width = this.Width - this.lblCount.Left - 
                         this.btnPrevious.Width -2; 
   //Center the logo 
   this.pictureBox1.Left = (this.Width/2)-(this.pictureBox1.Width/2); 
   this.pictureBox1.Top = (this.Height/2)-(this.pictureBox1.Height/2); 
   //Center the progress bar 
   this.progressBar1.Width = (this.Width*75)/100; 
   this.progressBar1.Left = (this.Width/2)-(this.progressBar1.Width/2); 
   this.progressBar1.Top = this.pictureBox1.Top+this.pictureBox1.Height+2; 

Visual Studio 2005 and Compact Framework V2 will have support for docking and anchoring of controls. Hopefully when this comes, you shouldn't have to do much manual work in adjusting your controls when the user decides to switch screen orientations. To find out what's in store for Windows Mobile 2003 SE check out

"Floating" Window

There is a lot of info available on creating a "floating" window so I won't go into too much detail. Basically what you have to do is set the following properties of the Form to false:

  • ControlBox
  • MinimizeBox
  • MaximizeBox


One other thing you may want to do is center your form on the screen. The following code will center the screen on the device:

// Center the screen
Rectangle _screen = Screen.PrimaryScreen.WorkingArea; 
this.Location =new Point(((this._screen.Width - this.Width) / 2),
                          ((this._screen.Height - this.Height) / 2));


Like I stated above, my primary reason for writing this is to try and win a Pocket PC but I also felt it's a pretty cool application. Is there much use for it, I don't know you tell me. I started it because the Google Search APIs are available and thought it would be cool to access them from a PocketPC. What the application does do is go through a few techniques for developing for the Compact Framework and hopefully it will be useful for some to see it all in one application. Don't forget to check out the first article. Also, the Google API exposes "Cache Requests" and "Spelling Requests". I haven't included these in this application and don't intend to (unless I am really bored!) but if someone does include it in this app drop me a line. I think the spelling request would be cool to use in some application. If you have any questions or comments you can contact me at or add comments below.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mark Arteaga
Canada Canada
Mark is a Software Development Consultant from Toronto, Ontario, Canada focusing on .Net Framework and Compact Framework projects. He has been in the computer industry for the past 6 years designing, architecting and leading various software projects. During the past three years his focus has been primarily on mobile projects utilizing Windows CE, Windows Mobile (PocketPC and SmartPhone) and .NET Compact Framework. He is also actively involved in the project which specifically targets improving the Microsoft .Net Compact Framework through open source projects.

Currently Mark is Software Development Consultant/President of Neoteric Software Development Company which specializes in software architecture, design, performance tuning/optimization and development in embedded and mobile solutions using Microsoft .NET Technologies.

Comments and Discussions

GeneralFind.ico Pin
LAleks21-May-04 2:35
memberLAleks21-May-04 2:35 
GeneralMissing Pictures Pin
Heath Stewart18-May-04 6:14
protectorHeath Stewart18-May-04 6:14 
GeneralRe: Missing Pictures Pin
Mark Arteaga18-May-04 7:11
memberMark Arteaga18-May-04 7:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 16 May 2004


40 bookmarked