Based on For Windows Mobile 5.0 Handheld weather forecast Design
Overview: DescribeFor Windows Mobile 5.0Weather forecastProgramDesign Process;
Development tools:Visual Studio 2005 (C #/) Windows Mobile 5.0 Pocket pc sdk/wm6Simulator;
Trial model: QidaD600
Keywords:. Net CF, PPC, WebService, Windows Mobile,Weather Forecast
Download the installer: pocketweatherinstall. Cab
DownloadSource code: Pocketweather.rar
In general. NET Compact frameworkThe design procedure is relatively easy to start with. This article gives a brief description of several problems encountered during the design process.
1.Weather Interface
Use a free onlineWebService, SourceWww.webxml.com.cn, Easy to use, callGetweatherbycitynameReturns a string array containing the weather information.
StringCity =This. Lblcurrentcity. Text. Trim ();
Pocketweather.cn.com. webxml. www.WeatherwebserviceWeather =
NewPocketweather.cn.com. webxml. www.Weatherwebservice();
String[] Info = weather. getweatherbycityname (city );
2.Obtain the program running path
PPCIt is still difficult to obtain the current program path:
Public Static StringGetapplicationdirectory ()
{
ReturnSystem. Io.Path. Getdirectoryname (
System. reflection.Assembly. Getexecutingassembly (). getname (). codebase );
}
3.Save User settings
Save User settings in a dataset and save them as local XML files:
DatasetDS =New Dataset("Lastweather");
DatatableTablast =New Datatable("Weather");
Tablast. Columns. Add ("Keystr",Typeof(String));
Tablast. Columns. Add ("Content",Typeof(String));
DatarowRow = tablast. newrow ();
Row ["Keystr"] ="Lbltodayweather";
Row ["Content"] =This. Lbltodayweather. text;
Tablast. Rows. Add (ROW );
Row = tablast. newrow ();
Row ["Keystr"] ="Lastmodifytime";
Row ["Content"] =Systemconfig. Lastmodifytime;
Tablast. Rows. Add (ROW );
DS. Tables. Add (tablast );
DS. writexml (Systemconfig. Getapplicationdirectory () +"Last. xml");
Get dataset from the XML file and then read the data.
DatasetDS =New Dataset();
DS. readxml (Systemconfig. Getapplicationdirectory () +"Last. xml");
DatatableTabsetting = Ds. Tables ["Weather"];
Datarow[] Rows = tabsetting. Select ("Keystr = 'lbltodayweather '");
If(Rows. length! = 0)
{
This. Lbltodayweather. Text = rows [0] ["Content"]. Tostring ();
}
Rows = tabsetting. Select ("Keystr = 'lastmodifytime '");
If(Rows. length! = 0)
{
Systemconfig. Lastmodifytime = rows [0] ["Content"]. Tostring ();
}
4.Input Method panel:
When the input method panel pops up, some user controls will be blocked and it feels bad. The solution is to place the control in a panel and set the autoscroll attribute of the Panel to true, when the Panel status changes, the Panel size is also changed.
PrivateMicrosoft. WindowsCE. forms.InputpanelM_indium
=NewMicrosoft. WindowsCE. forms.Inputpanel();
PublicFormopetion ()
{
Initializecomponent ();
This. M_inp.enabledchanged + =New Eventhandler(M_inp_enabledchanged );
}
VoidM_inp_enabledchanged (ObjectSender,EventargsE)
{
M_panel.size = m_inp.visibleshorttop.size;
}
5.Dialog Box:
When the program opens a dialog box, if you switch to another program, and then you will see two records in the list of system running programs, you should avoid this situation; the solution is to modify the window title when the program is activated or stopped:
Private VoidFormopetion_deactivate (ObjectSender,EventargsE)
{
This. Text ="";
}
Private VoidFormopetion_activated (ObjectSender,EventargsE)
{
This. Text ="Set";
}
6.Others:
You should also consider re-adjusting the widget position when rotating the screen.
Interface: