TOM快跑综合论坛

首页 » IT版块 » TOM快跑---电脑技术 » 转贴:Windows Mobile 5.0 开发学习
明王 - 2008-2-29 15:57:00
自上星期以来,开始系统化的学习Windows Mobile 5.0,希望通过系统化的学习,能够掌握移动开发。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile 5.0开发配置:
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
软件安装顺序:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1. 安装Microsoft ActiveSync 4.0以上版本z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2. 安装VS2005z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
开发Pocket PC需安装Windows Mobile 5.0 Pocket PC SDKz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
开发Smartphone需安装Windows Mobile 5.0 Smartphone SDKz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile 5.0环境配置:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1. 模拟器与Microsoft ActiveSync同步:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
A.启动VS2005,在Tools->Device Emulator Manager,选择一个需要启动的模拟器,双击或者按右键,选择“Connect”,即启动模拟器。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
B. 当模拟器启动后,在Device Emulator Manager中,右键该设备,选择“Cradle”,即可与Microsoft ActiveSync同步。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2. 模拟器上网:
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
启动模拟器后,只要PC机连接网络,模拟设备即能上网。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3.可能出现模拟器与Microsoft ActiveSync无法同步的现象,这种情况很可能发生,出现该情况,可以关闭VS2005,关闭Device Emulator Manager,然后再重新启动即可。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
  Mobile 5.0 最初的开发程序:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Pocket Pc上新建1个应用程序:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在File->New->Project中可以选择Pocket PC或者Smartphone的Device Applicationz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
项目新建以后所看到的Form的界面是和真实设备的界面完全一致。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Form上放置1个TextBox后,将值改成Pocket PC,运行该程序z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Pocket Pc右上角的有2种按钮,叉和ok,叉代表最小化,ok代表关闭。最小化程序会使得程序占用内存,在此觉得微软的操作系统提供的程序有些都是最小化,没有释放内存,会使得系统越跑越慢。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
将最小化变为ok,通过设置form的属性MinimizeBox,true为最小化按钮,false为ok按钮。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Smartphone中没有上述的变化,在Smartphone中,如果不添加menu中的事件来结束程序的话,那程序始终会以最小化方式保留在系统内部。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
更改应用程序的平台:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
选择project,右键,在菜单中选择“Change Target Platform”z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在选择平台中,选择一个你想改变的平台,按OK即可
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
注:Pocket Pc和SmartPhone平台改换后,要更改下列内容:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1. 控件的大小z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2. 某些特定控件在SmartPhone中不支持,如Buttonz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3. 某些托管API。SmartPhone中,所支持的API没有Pocket PC多z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
开发Mobile需要注意:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
由于是基于移动设备的,所以无论cpu还是内存来说,都和PC有很大差距,所以要求消耗较少的内存开销,另外相比PC来说,所支持的API是非常少的,需要经常查SDK。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
  在开发Mobile Web Site之前,准备工作:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1. 确认IIS可以正常启动。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2. VS2005能够以HTTP方式正常创建Web Site。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3. 至少有1个模拟器,Pocket PC,Smartphone,Openwave。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
新建1个空的站点,在站点中添加一个Mobile Web Form,命名为index.aspx。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
将该页面切换到Design模式,可以发现页面上的Form的宽度非常小而且是固定的,这是因为该页面与实际设备上显示的页面会保持一致。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
控件的breakAfter属性,true表示控件render后会多添加一个换行符。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form与Web Form之间的区别:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1. 控件Tag标签:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
      Web Form:控件标签都以<asp:xxxx></asp>,atlas以前是以<atlas:xxxx></atlas>,现在也都统一成z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                          <asp:xxxx></asp>形式了。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
      Mobile Web Form:控件标签以<mobile:xxxx></mobile>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2. Mobile Web Form中可以添加的控件:(在Design中,Toolbox中)z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
      Standard:只能用于WM操作。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
      Mobile Web Form:可以适用于任何移动设备浏览器,可能显示效果不一样,特殊控件需要根z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                                      据设备进行效果调整。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3. Mobile Web Form上可以放置多个Form,而Web Form只能有1个Form。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
4. Mobile Web Form不支持MasterPage,而Web Form支持。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
一个站点中可以包含Web Form和Mobile Web Form,Mobile Web Form上的控件推荐都采用Toolbox中Mobile Web Form面板内的控件。针对不同平台的浏览器,定制一些适用于该平台的设置,Mobile Web Form中的所有Mobile控件都支持定制。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
控件定制:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在控件的Properties的Property Overrides,选择Edit按钮,在Applied Device Filters中选择一个过滤器,选择好后按Edit编辑参数,Compare用于根据什么比较,Argument是该如果比较项等于该参数就满足该过滤器的条件,就可以按照你自己定义的这个效果显示。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form的数据邦定控件ObjectList Control
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
可以用DataSource指定数据源,支持Template,共有3类Template。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1.Header and Footer Templatesz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2.Item Templatesz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3.Separator Template。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
补充:一旦设置了某个Template,那默认的显示就消失了。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
我只设置了Header和Footer,并没有设置Item,但是系统为认为Item也是设置的,只不过没有内容而已。另外,只有为ObjectList Control控件定制以后才能进行Template的编辑。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Mobile Web Form上可以放置多个Form,Form的形式是以组件的形式加载的,当用户对该Form所在的Web Form发出请求后,就会将该Web上的所有Form全部加载,以减少在切换Form时的时间。同一Web上的不同Form间切换只传递的是一些数据,具体可以使用Openwave后看下请求和相应效果。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
另外对于Openwave,由于在Openwave sdk 6.2.2中页面的button会显示出来,而不是当焦点移过去后,SoftKey左键会有button的显示,较早版本的Openwave中会有该效果的。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
参考文章:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Customizing ASP.NET Mobile Web Controls for Specific Devicesz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
补充在(2)中的内容:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form与Web Form的区别:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form不支持Theme,但Mobile Web Form可以使用StyleSheet。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
修改(1)的内容:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
当模拟器和Microsoft ActiveSync无法同步时,可以按照下列步骤就可以立即恢复同步。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1.在Tools->Device Emulator Manager中,选择正在同步的设备右键,选择"Uncradle"。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2.打开Microsoft ActiveSync,按connect,这时候会出现同步画面。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3.在Tools->Device Emulator Manager中,选择"Cradle"继续同步。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile页面上调用所有Asp.net的控件必须订制。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Mobile Web Form中使用javascript的方法:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
由于有些手机能够支持javascript,所以只有支持javascript的手机才能显示出效果,所以需要定制,在支持的手机中实现javascript效果。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
涉及代码:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
<mobile:Form id="Form1" runat="server" OnLoad="Form1_Load">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Label ID="Label1" Runat="server" Font-Bold="True">Student Name:</mobile:Label>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:TextBox ID="txtStName" Runat="server"></mobile:TextBox>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click1">Get Info</mobile:Command>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Command ID="Command2" Runat="server">Client Event</mobile:Command>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Panel ID="Panel1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
           
<mobile:DeviceSpecific ID="DSP1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
               
<Choice Filter="isHTML32" Xmlns="http://schemas.microsoft.com/mobile/html32template">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<ContentTemplate>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<asp:CheckBox ID="chkBox" runat="server" Text="CheckBox Control"z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
/>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<Script language="jscript" for="window" event="onload">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            window.Form1.Command1.onclick
= ShowMsg;z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                           
function ShowMsg(e)z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                           
{z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                                alert(
"Msg!");z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            }
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
</Script>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
<Script language="jscript" for="Command2" event="onclick">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            alert(
"Msg!");z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
</Script> z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
</ContentTemplate>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
               
</Choice>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
           
</mobile:DeviceSpecific>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
</mobile:Panel>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
   
</mobile:Form>
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
其中在panel中放置定制<mobile:DeviceSpecific ID="DSP1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
定制条件是只要支持HTML就行<Choice Filter="isHTML32">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在ContentTemplate中插入script代码,其中for是针对的控件,Mobile Web Form中用window代替document。Event表示对于指定的控件,出现指定的事件时执行scipt中的操作。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
第一个script中,当页面onload的时,执行script,并指定command1的onclick事件。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
第二个script中,只有当command2点击时,才执行script。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在ContentTemplate中就能添加asp.net控件,更能添加atlas等。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
关于script的属性可以看MSDN的SCRIPT Element | script Objectz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
里面对script的每个属性,使用方法都有实例。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
补充在(2)中的内容:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form与Web Form的区别:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form不支持Theme,但Mobile Web Form可以使用StyleSheet。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
修改(1)的内容:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
当模拟器和Microsoft ActiveSync无法同步时,可以按照下列步骤就可以立即恢复同步。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1.在Tools->Device Emulator Manager中,选择正在同步的设备右键,选择"Uncradle"。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2.打开Microsoft ActiveSync,按connect,这时候会出现同步画面。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3.在Tools->Device Emulator Manager中,选择"Cradle"继续同步。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile页面上调用所有Asp.net的控件必须订制。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Mobile Web Form中使用javascript的方法:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
由于有些手机能够支持javascript,所以只有支持javascript的手机才能显示出效果,所以需要定制,在支持的手机中实现javascript效果。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
涉及代码:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
<mobile:Form id="Form1" runat="server" OnLoad="Form1_Load">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Label ID="Label1" Runat="server" Font-Bold="True">Student Name:</mobile:Label>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:TextBox ID="txtStName" Runat="server"></mobile:TextBox>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click1">Get Info</mobile:Command>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Command ID="Command2" Runat="server">Client Event</mobile:Command>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Panel ID="Panel1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
           
<mobile:DeviceSpecific ID="DSP1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
               
<Choice Filter="isHTML32" Xmlns="http://schemas.microsoft.com/mobile/html32template">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<ContentTemplate>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<asp:CheckBox ID="chkBox" runat="server" Text="CheckBox Control"z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
/>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<Script language="jscript" for="window" event="onload">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            window.Form1.Command1.onclick
= ShowMsg;z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                           
function ShowMsg(e)z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                           
{z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                                alert(
"Msg!");z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            }
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
</Script>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
<Script language="jscript" for="Command2" event="onclick">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            alert(
"Msg!");z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
</Script> z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
</ContentTemplate>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
               
</Choice>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
           
</mobile:DeviceSpecific>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
</mobile:Panel>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
   
</mobile:Form>
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
其中在panel中放置定制<mobile:DeviceSpecific ID="DSP1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
定制条件是只要支持HTML就行<Choice Filter="isHTML32">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在ContentTemplate中插入script代码,其中for是针对的控件,Mobile Web Form中用window代替document。Event表示对于指定的控件,出现指定的事件时执行scipt中的操作。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
第一个script中,当页面onload的时,执行script,并指定command1的onclick事件。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
第二个script中,只有当command2点击时,才执行script。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在ContentTemplate中就能添加asp.net控件,更能添加atlas等。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
关于script的属性可以看MSDN的SCRIPT Element | script Objectz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
里面对script的每个属性,使用方法都有实例。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
补充在(2)中的内容:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form与Web Form的区别:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile Web Form不支持Theme,但Mobile Web Form可以使用StyleSheet。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
修改(1)的内容:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
当模拟器和Microsoft ActiveSync无法同步时,可以按照下列步骤就可以立即恢复同步。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1.在Tools->Device Emulator Manager中,选择正在同步的设备右键,选择"Uncradle"。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
2.打开Microsoft ActiveSync,按connect,这时候会出现同步画面。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
3.在Tools->Device Emulator Manager中,选择"Cradle"继续同步。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile页面上调用所有Asp.net的控件必须订制。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Mobile Web Form中使用javascript的方法:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
由于有些手机能够支持javascript,所以只有支持javascript的手机才能显示出效果,所以需要定制,在支持的手机中实现javascript效果。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
涉及代码:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
<mobile:Form id="Form1" runat="server" OnLoad="Form1_Load">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Label ID="Label1" Runat="server" Font-Bold="True">Student Name:</mobile:Label>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:TextBox ID="txtStName" Runat="server"></mobile:TextBox>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click1">Get Info</mobile:Command>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Command ID="Command2" Runat="server">Client Event</mobile:Command>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
<mobile:Panel ID="Panel1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
           
<mobile:DeviceSpecific ID="DSP1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
               
<Choice Filter="isHTML32" Xmlns="http://schemas.microsoft.com/mobile/html32template">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<ContentTemplate>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<asp:CheckBox ID="chkBox" runat="server" Text="CheckBox Control"z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
/>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
<Script language="jscript" for="window" event="onload">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            window.Form1.Command1.onclick
= ShowMsg;z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                           
function ShowMsg(e)z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                           
{z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                                alert(
"Msg!");z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            }
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
</Script>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
<Script language="jscript" for="Command2" event="onclick">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                            alert(
"Msg!");z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                       
</Script> z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
                   
</ContentTemplate>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
               
</Choice>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
           
</mobile:DeviceSpecific>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
       
</mobile:Panel>z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
   
</mobile:Form>
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
其中在panel中放置定制<mobile:DeviceSpecific ID="DSP1" Runat="server">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
定制条件是只要支持HTML就行<Choice Filter="isHTML32">z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在ContentTemplate中插入script代码,其中for是针对的控件,Mobile Web Form中用window代替document。Event表示对于指定的控件,出现指定的事件时执行scipt中的操作。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
第一个script中,当页面onload的时,执行script,并指定command1的onclick事件。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
第二个script中,只有当command2点击时,才执行script。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在ContentTemplate中就能添加asp.net控件,更能添加atlas等。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
关于script的属性可以看MSDN的SCRIPT Element | script Objectz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
里面对script的每个属性,使用方法都有实例。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
Mobile程序部署:将自己开发的Mobile WinForm程序部署到设备上。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
新建1个Project,该程序启动后就显示系统时间。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
程序很简单,就是在Form_Load事件中,将Label的Text值设置为系统时间。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
编译后,运行到模拟设备上,进行测试。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
程序显示正常,那可以进行部署了。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Solution中添加1个Project,选择Solution->Add->New Projectz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
选择Other Project types->Setup And Deployment->Smart Device CAB Projectz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
新建1个CAB的Project。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
新建完后,出现配置界面:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在File System on Target Machine中可以添加不同的文件夹,在不同的文件夹内可以添加相应的处理。默认的情况会有Application Folder和Program Files Folder这2个文件夹,但里面内容都是空的。
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
为了在设备上的Start Menu菜单和Programs文件夹内有快捷方式,我添加了这2个文件夹。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Application Folder中添加程序主体:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Application Folder中添加一个Project Output,选择Primary output
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
快捷方式的添加:z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
选择一个Folder,在旁边一栏,右键选择Create New Shortcut,在对话框中选择Application Folder,将Primary output添加进来。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Solution Explorer中,选择CAB Project中的Primary output,打开它的属性z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在Outputs中可以察看部署到设备中的实际的内容。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
打开ActiveSync程序,选择Explorez7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
我将CAB复制到设备中。然后打开设备,在文件管理器中执行该CABz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
安装完毕后,查看Start菜单,程序部署成功。z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
在图中的DemoDeployment是我的WinForm的Project名z7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
http://www.sf.org.cn/windowsmobile/windowsmobilerumen/Index.htmlz7æ„Ý-‘bbs.tomrun.net>5)‘ø¼÷
1
查看完整版本: 转贴:Windows Mobile 5.0 开发学习