<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      桌面端的移動運算(二)

      [摘要]Working with the RAPI Class為了簡化RAPI類的操作,我將添加一個using聲明到示例程序的C#版本,或添加一個Imports聲明到VB.NET中,示例如下:[VC#.NE...
      Working with the RAPI Class
      為了簡化RAPI類的操作,我將添加一個using聲明到示例程序的C#版本,或添加一個Imports聲明到VB.NET中,示例如下:

      [VC#.NET]
      using OpenNETCF.Desktop.Communication;
      [VB.NET]
      Imports OpenNETCF.Desktop.Communication
      另外,我將添加一個單獨的module-level變量,myrapi,用于保存一個RAPI類的實例。

      [VC#.NET]
      // Declare an instance of the RAPI object.
      RAPI myrapi;
      [VB.NET]
      ' Declare an instance of the RAPI object.
      Dim WithEvents myrapi As New rapi
      Connecting to the Device
      當你的桌面程序使用RAPI類時,第一步是要與設備建立一個連接。

      注意:在桌面程序中使用RAPI必須要有一個PC與設備之間的激活的ActiveSync連接。

      在這篇文章包含的示例程序中,在Form_Load事件中將連接到設備。為了連接到設備,你使用RAPI類的Connect方法。正如下面代碼所演示的,我緊接著檢查了RAPI類的DevicePresent屬性,來校驗連接是否成功。

      [VC#.NET]
      try

      // Connect to the device.
      {
      myrapi.Connect();
      while (! myrapi.DevicePresent)
      {
      MessageBox.Show("Please connect your device to your PC using
      ActiveSync and before clicking the OK button.",
      "No Device Present");
      myrapi.Connect();
      }
      }

      catch (Exception ex)
      {
      MessageBox.Show("The following error occurred while attempting
      to connect to"+ " your device - " + ex.Message,
      "Connection Error");
      Application.Exit();
      }
      [VB.NET]
      Try
      ' Connect to the device.
      myrapi.Connect()
      Do While Not myrapi.DevicePresent
      MessageBox.Show("Please connect your device to your PC using
      ActiveSync and " & _
      "before clicking the OK button.", "No Device Present")
      myrapi.Connect()
      Loop

      Catch ex As Exception
      MessageBox.Show("The following error occurred while attempting to
      connect to" & _
      " your device - " & ex.Message, "Connection Error")
      Application.Exit()
      End Try
      在連接確定后,我們將準備來探索RAPI提供的功能了。我們將從在你的桌面程序中如何管理設備的文件夾和文件開始。

      Working with Files
      RAPI提供了很多的功能為了操作文件夾中的文件。我將選擇示范三個文件相關的屬性:從設備上拷入、拷出文件,在設備上移動文件,在設備上刪除文件。我們先來看一下拷貝文件。

      Copying Files To and From a Device
      與設備交換數據最容易的方式之一就是簡單地在設備與PC間拷貝一個文本或者XML文件。該操作的使用RAPI示例程序的界面如圖一。文本和基于XML的文件可以在移動應用程序中作為存儲應用程序數據或配制數據的簡單方式。


      Figure 1. The Copy File tab of the RAPI demo program.

      OpenNETCF.Desktop.Communication命名空間RAPI類提供了兩個方法來拷貝文件——CopyFileToDevice 和 CopyFileFromDevice。這兩個方法都將源文件作為第一個參數,而目的文件作為第二個參數。

      BtnCopyPerform按鈕的點擊事件處理過程里演示了這些方法。究竟是CopyFileToDevice 或者 CopyFileFromDevice方法被調用,要依賴于用戶通過用戶界面上的Combo Box進行選擇。

      [VC#.NET]
      private void btnCopyPerform_Click(object sender, System.EventArgs e)
      {

      // Perform the copy.
      try
      {
      if ((txtCopySource.Text == "") (txtCopyDestination.Text == ""))
      {
      MessageBox.Show("You must provide both a source and destination
      file.",
      "Missing File Information");
      }
      else
      {
      switch (cmbCopyDirection.Text)
      {
      case "":
      MessageBox.Show("You must select a direction before initiating
      the copy.",
      "No Destination Selected");
      break;
      case "from desktop to device":
      myrapi.CopyFileToDevice(txtCopySource.Text,
      txtCopyDestination.Text);
      MessageBox.Show("Your file has been copied.", "Copy Success");
      break;
      case "from device to desktop":




      日韩精品一区二区三区高清