Window

Q1
画面の縦長・横長の切り替えに合わせてオブジェクトの位置を変更したい

A1
[解決方法]
画面の縦・横の状態に合わせて、オブジェクト位置やサイズを変更するには、
参照演算子と 3項演算子を利用します。

■ 例 1
  Button Button1 {
   :
  Width &= Form1.Width < 320 ? 80:100;
   :
}
 
Form1のWidthを都度参照し、その値が 320より小さい(縦長画面)場合、
Button1のWidthは「80」にし、320以上(横長画面)の場合、「100」に
しています。


■ 例 2
  Form Form1 {

  /* 画面の縦・横切り替えを識別する為のフラグを定義 */
  Number kirikae_flg {

    Value &= Form1.Width < 320 ? 0 : 1;
    UseChange = $TRUE;

    Function OnChange(e){
      if( Value ){
        ^.Button1.Width = 100;
          :
      }else{
        ^.Button1.Width = 80;
          :
      }
    }
  }
  Button Button1{
    :
  }
}
 
Formの子オブジェクトとして、Numberオブジェクトなど表示されない
オブジェクトをフラグとして定義し、フラグにFormのサイズの変化を代入、
フラグの値の変化を参照し、Buttonオブジェクトのサイズを変更しています。
画面内のオブジェクトが多く、参照演算子を多用できない場合や、サイズ
切り替えのロジックを一箇所にまとめて記述したい場合に効果的です。



Formのサイズについては、Biz/Browser Mobile・Biz/Browser for PDA TIPS集 >
   Window > デザイン可能な画面サイズは?
をご参照ください。


[サンプルコード]



サンプルコードは、
  「画面の縦横切り替えサンプル (mobA002Sample.zip)
をご参照ください。

管理番号:BMP_A002
  Biz-Collections Bizの宝箱 トップへ
  Biz/Browser Mobile・Biz/Designer Mobile TIPS集 トップへ