方法 : 画面の回転のハンドル

[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]

画面の向き縦以外の Direct3D アプリケーションを開発できます。 ただし、デバイス ドライバー提供さまざまなレベルのサポート、非-縦方向に描画用アプリケーション画面回転を処理するための推奨のプラクティスに従う必要がありますように。

注意

マネージの Direct3D モバイル アプリケーションが、Pocket PC やスマートフォン Windows Mobile 5. 0 ソフトウェアを必要です。.NET の外部のリソース フレームワークを最適化します。 Windows Mobile ソフトウェアおよび SDK についてを参照してください。

次のコード例は、Windows Software Development Kit (SDK) に。

画面を回転した状態にあることを検出するには

  1. プロジェクトに、Microsoft.WindowsCE.Forms コンポーネントへの参照を追加します。

  2. 検出コードを追加する最も簡単な方法は、メイン フォームの Resize イベント ハンドラー内にです。 フォームのコンストラクターでイベント ハンドラーのデリゲートを追加します。

    this.Resize += new System.EventHandler(this.MyForm_Resize);
    
    AddHandler Resize, AddressOf Me.MyForm_Resize
    
  3. 印刷の向きが変更されたときに追跡するをブール型 (Boolean) orientationChanged クラス メンバー変数を追加します。 ScreenOrientation プロパティの値を使用して、現在の向きを決定します。 Angle0 の値を縦向きモードを示します。 現在の向きをすると異なる場合、書きとめて、orientationChanged フラグを設定しておきます。 通常は何この時点で、アプリケーションがバックグラウンドでためです。 操作しないプログラムで変更の向きをここで、サイズ変更イベントを発生させた方向変更がまだ完了いない可能性があります。 戻る方向を変更しようとした場合ここで失敗します。

        // Add a class member variable to
        // store that the orientation has changed.
        bool orientationChanged = false;
    
        private void MyForm_Resize(object sender, EventArgs e)
        {
           if (SystemSettings.ScreenOrientation !=
             ScreenOrientation.Angle0)
            orientationChanged = true;
        }
    
        ' Add a class member variable to
        ' store that the orientation has changed.
        Dim OrientationChanged As Boolean = False
    
    Private Sub MyForm_Resize(ByVal sender As Object, ByVal e As EventArgs)
        If (SystemSettings.ScreenOrientation <> ScreenOrientation.Angle0) Then
           orientationChanged = True
        End If
    End Sub
    

画面が回転するときにアクションを実行する方法

  • 各フレームの向きが変更されたかどうかを確認を確認できます。 次のコード例の CheckRotation メソッドでは、画面の向きを縦モードに ScreenOrientation プロパティの設定によって変わります。 目的のユーザー エクスペリエンスに応じて他のアクションを取るを検討します。 たとえばに適用してそれ自体、画面の向きを変えるしないがユーザーはそれを戻す変更しない限り、レンダリングが続行されないことをユーザー代わりに通知することがあります。 画面の向きを変更する場合も保存してください次の例のように、初期画面の向き] を復元します。 画面の向きを変更しないでによって他のアクションを代わりに実行する場合は、レンダリングが引き続き通常どおりがサイレント モードでは、失敗または例外を返す失敗その可能性があります。

    それがいない場合) で縦モードで縦向きモードのデバイスにしようとコード例を次に示します。 CheckOrientation メソッドは、デバイスが縦画面モードである場合、 true を取得します。

    private bool CheckOrientation()
    {
        // orientationChanged is set to true in resize if it is
        // detected that the orientation of the device has changed.
        if (orientationChanged)
        {
          // Attempt to change the display back to portrait mode.
          try
          {
             SystemSettings.ScreenOrientation =
              ScreenOrientation.Angle0;
             // Now that the orientation is back to portrait mode
             // Do not attempt to change it again.
             orientationChanged = false;
           }
          catch (Exception)
          {
             // Failed to change the display mode.
             return false;
          }
        }
        return true;
    }
    
    // Use the CheckOrientation() method before rendering occurs.
    // All rendering for each frame occurs here.
    
    private void Render()
    {
        // If the device is not oriented properly, 
        // some display drivers may not work.
        if (!CheckOrientation())
            return;
            // Rendering code omitted here.
    }
    
    Private Function CheckOrientation() As Boolean
        ' orientationChanged is set to true in resize if it is
        ' detected that the orientation of the device has changed.
        If orientationChanged Then
            ' Attempt to change the display back to portrait mode.
            Try 
                SystemSettings.ScreenOrientation = ScreenOrientation.Angle0
                ' Now that the orientation is back to portrait mode
                ' Do not attempt to change it again.
                orientationChanged = false
            Catch  As Exception
                ' Failed to change the display mode.
                Return false
            End Try
        End If
        Return true
    End Function
    
    ' Use the CheckOrientation() method before rendering occurs.
    ' All rendering for each frame occurs here.
    Private Sub Render()
        ' If the device is not oriented properly, 
        ' some display drivers may not work.
        If Not CheckOrientation Then
            Return
        End If
        ' Rendering code omitted here.
    End Sub
    

アプリケーション終了時に、印刷の向きを復元するには

  • 画面の向きをプログラムで変更する場合は、アプリケーション終了時に、アプリケーションの初期の向きも復元する必要があります。 アプリケーションが実行中に向きを変更すると、ため、初期の向きを保存をアプリケーション終了時に元に戻す必要があります。 初期の向きを格納するメンバー変数を追加します。

    ScreenOrientation initialOrientation = SystemSettings.ScreenOrientation;
    
    ScreenOrientation initialOrientation = SystemSettings.ScreenOrientation;
    

    このアプリケーションの終了するときに、印刷の向きを復元しようとする Main メソッドの末尾に追加します。

    if (SystemSettings.ScreenOrientation != initialOrientation)
    {
        try
        {
           SystemSettings.ScreenOrientation = initialOrientation;
        }
        catch (Exception)
        {
            // Unable to change the orientation back 
            // to the original configuration. 
    
            MessageBox.Show("This sample was unable to set the " +
                "orientation back to the original state.");
        }
    }
    
    If (SystemSettings.ScreenOrientation <> initialOrientation) Then
        Try 
            SystemSettings.ScreenOrientation = initialOrientation
        Catch  As Exception
            ' Unable to change the orientation back 
            ' to the original configuration. 
            MessageBox.Show(("This sample was unable to set the " & _
                "orientation back to the original state."))
        End Try
    End If
    

参照

概念

.NET コンパクトなフレームワーク方法を説明したトピックの検索

その他の技術情報

.NET Compact Framework でモバイル Direct3D プログラミング