随笔-348  评论-598  文章-0  trackbacks-0

1.如何真正的退出程序,而不是隐藏窗体?
Windows Mobile中当你点击X的时候,并不是真正的关闭窗体,而是隐藏窗体,需要在应用程序的每个Form中调用一个函数才可以。

        private void InfoMain_Closed(object sender, EventArgs e)
        
{
            Application.Exit();
        }


每个窗体的Closed事件中加入Application.Exit();才能真正的退出程序。

2.如何让窗体跟着输入法窗口上移
当输入文字时需要打开输入法,而当打开输入法的时候输入法会直接盖掉下层的程序界面,导致有时候窗体下方的控件无法进行操作(输入文字,点击按钮等),那么这个时候就需要我们在输入法状态变更的时候出发一些事件,让输入法窗口不要盖住程序。
首先每次创建Form,最好都先添加一个panel做控件的上层容器,设定好相对panel的位置,这样控件才会根据panel的变化而变化。之后给InputPanel的EnabledChanged事件加入下面的代码:

        private void inputPanel1_EnabledChanged(object sender, EventArgs e)
        
{
            
if (inputPanel1.Enabled)
            
{
                
this.panel1.Dock = DockStyle.None;
                
this.panel1.Height = inputPanel1.VisibleDesktop.Height;
            }

            
else
            
{
                
this.panel1.Dock = DockStyle.Fill;
            }

        }
当输入法打开的时候panel不再占据全屏,而是跟除了输入法外的可视化范围一样高。输入法关闭时,panel恢复占据全屏。当然panel的AutoScroll要设定为true。

3.如何创建非全屏Form?
首先需要你创建一个全屏的Form,然后将以下参数设定为指定值
ControlBox = false;
FormBorderStyle = none;
MinimizeBox = false;
WindowState = normal;
Size = 设置为你想要的大小即可。

这样的非全屏窗体不带边框不带标题,只有一个光秃秃的Form。如果你需要那些边框和标题使得界面更加美观,则可以参考以下文章:
http://www.christec.co.nz/blog/archives/134
牵扯到了一些对底层的操作。

4.【实用技巧】Windows Mobile 手机连接电脑时,如何使用GPRS上网,同时跟电脑保持连接。(USB和GPRS共存问题) (3-19 22:08)

5.如何提高Windows Mobile中 Http上传文件的稳定性?
其实上传文件最好还是用FTP,因为比较稳定,各方面也很成熟。如果是和业务系统相关的一些东西,也不要紧,客户端上传完成之后请求下服务端的一个服务,通知他业务数据上传完毕,然后服务端去做一些操作,之后可以回应给客户端就可以了。
但如果非要用HTTP的话,也不要紧,虽然无线网络用HTTP传输文件不是太稳定,但总体上还是不错的,只是你需要设计一套断点续传机制,来保证就算网络发生异常了,也可以接着上次的再传。除了使用断点续传机制,还有一个技巧,就是让客户端和服务端的连接超时时间(ConnectionTimeout)尽可能的长些,比如设置为200秒,这是在开发过程中总结出来的,我测试过很多次,发现如果超时时间很长的话,多数大文件(> 500kb)其实一次就可以传递上去,之前传不上去,多数是因为连接超时,而服务端如果使用tomcat,抛出Socket read timeout异常之后,客户端多数收不到,因为此时的客户端还在朝Request中的Outputstream写数据,还没有走到request.GetResponse()这一步,这就造成了,客户端发送完数据之后才知道客户端异常了,浪费了很多流量,也降低了很多效率,大家可以注意一下。

6.如何建立GPRS连接?
移动:
XmlDocument configDoc = new XmlDocument();
configDoc.LoadXml(
                        
"<wap-provisioningdoc>" +
                        
"<characteristic type=\"CM_GPRSEntries\">" +
                        
"<characteristic type=\"xxx\">" +
                        
"<parm name=\"DestId\" value=\"{ADB0B001-10B5-3F39-27C6-9742E785FCD4}\" />" +
                        
"<parm name=\"UserName\" value=\"1\" />" +
                        
"<parm name=\"Password\" value=\"1\" />" +
                        
"<parm name=\"Domain\" value=\"\" />" +
                        
"<characteristic type=\"DevSpecificCellular\">" +
                        
"<parm name=\"GPRSInfoValid\" value=\"1\" />" +
                        
"<parm name=\"GPRSInfoAccessPointName\" value=\"xx.js\" />" +
                        
"</characteristic>" +
                        
"</characteristic>" +
                        
"</characteristic>" +
                        
"</wap-provisioningdoc>"
                        );
ConfigurationManager.ProcessConfiguration(configDoc, 
false);
电信:
XmlDocument configDoc = new XmlDocument();
configDoc.LoadXml(
                        
"<wap-provisioningdoc>" +
                        
"<characteristic type=\"CM_GPRSEntries\">" +
                        
"<characteristic type=\"jsmsa\">" +
                        
"<parm name=\"DestId\" value=\"{ADB0B001-10B5-3F39-27C6-9742E785FCD4}\" />" +
                        
"<parm name=\"UserName\" value=\"xxxx.js\" />" +
                        
"<parm name=\"Password\" value=\"xxxx\" />" +
                        
"<parm name=\"Domain\" value=\"\" />" +
                        
"<parm name=\"Phone\" value=\"#777\"/>" +
                        
"<parm name=\"DeviceType\" value=\"modem\"/>" +
                        
"<parm name=\"DeviceName\" value=\"Cellular Line\"/>" +
                        
"<parm name=\"Enabled\" value=\"1\"/>" +
                        
"<parm name=\"RequirePw\" value=\"1\"/>" +
                        
"<parm name=\"DeviceSpecificRAW\" value=\"b4010000b4010000b4010000010000000f0000000100000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"/>" +
                        
"</characteristic>" +
                        
"</characteristic>" +
                        
"</wap-provisioningdoc>"
                        );
ConfigurationManager.ProcessConfiguration(configDoc, 
false);
修改连接的优先级:
                string configpreferred = " <wap-provisioningdoc> " +
                                         
" <characteristic   type=\"cm_planner\"" +
                                         
" <characteristic   type=\"preferredconnections\"" +
                                         
" <parm   name=\"{ADB0B001-10B5-3F39-27C6-9742E785FCD4}\"    value=\"jsmsa\"   /> " +
                                         
" </characteristic> " +
                                         
" </characteristic> " +
                                         
" </wap-provisioningdoc> ";

7.发起和断开连接
这两个方法需要另外两个类的协助
       public static void MakeConnection()
        {
            
try
            {
                ConnectionManager connectManager 
= new ConnectionManager();
                
int idx = -1;
                List
<ConnectionManager.CONNMGR_DESTINATION_INFO> lstIdentifiers = connectManager.EnumConnDestinations();

                
for (int i = 0; i < lstIdentifiers.Count; i++)
                {
                    
if ("Internet 连接".Equals(lstIdentifiers[i].Description))
                    {
                        idx 
= i;
                        
break;
                    }
                }

                
if (idx > -1)
                {
                    connectManager.EstablishConnection((
uint)idx);
                }
            }
            
catch
            {
            }
        }

 

        public static void Disconnect()
        {
            
try
            {
                RASManager.RASCONN[] conns 
= RASManager.GetRASConnections();
                
if (conns != null && conns.Length > 0)
                {
                    
foreach (RASManager.RASCONN conn in conns)
                    {
                        
try
                        {
                            RASManager.HangUp(conn.hRasConnHandle);
                        }
                        
catch (Exception ex)
                        {
                        }
                    }
                }
            }
            
catch
            {
            }
        }



---------------------------------------------------------
专注移动开发

Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2008-10-07 13:02 TiGERTiAN 阅读(1797) 评论(0)  编辑  收藏 所属分类: DotNetWindows Mobile

只有注册用户登录后才能发表评论。


网站导航: