[サンプルコード]
・PulldownListオブジェクトのChangeイベントの例
ChangeイベントはPulldownListオブジェクトのValueプロパティが変更されたことに
より発生するイベントですのでPulldownListオブジェクトのValueプロパティの
参照が可能です。
PulldownListオブジェクトのUseChangeプロパティを$TRUEに設定しておきます。
Form Form1 {
X = 0;
Y = 0;
Width = 400;
Height = 300;
PulldownList PulldownList1 {
X = 5;
Y = 5;
Width = 155;
Height = 110;
UseChange = $TRUE;
PulldownItem PulldownItem1[0];
Function OnChange( e ) {
var i = e.From.value;
/* var i = value; も可 */
switch(i){
case 0:
^.Label1.BgColor = $RED;
break;
case 1:
^.Label1.BgColor = $BLUE;
break;
case 2:
^.Label1.BgColor = $YELLOW;
break;
}
}
PulldownItem1 << CSV ( .title, .value ){
項目1,1
項目2,2
項目3,3
};
}
Label Label1 {
X = 165;
Y = 5;
Width = 50;
Height = 20;
}
if ( !$DESIGNTIME ) {
}
}
・PulldownItemオブジェクトのTouchイベントの例
Form Form1 {
X = 0;
Y = 0;
Width = 400;
Height = 300;
PulldownList PulldownList1 {
X = 5;
Y = 5;
Width = 155;
Height = 110;
UseChange = $FALSE;
PulldownItem PulldownItem1[0] {
Function OnTouch( e ) {
var i = e.From.index;
switch(i){
case 0:
^.^.Label1.BgColor = $RED;
break;
case 1:
^.^.Label1.BgColor = $BLUE;
break;
case 2:
^.^.Label1.BgColor = $YELLOW;
break;
}
/* 誤ったコーディング
var idx;
for( idx = 0; idx < ^.PulldownItem1.length; idx++ ){
if( ^.PulldownItem1[idx].Selected == $TRUE ){
switch( idx ){
case 0:
^.^.Label1.BgColor = $RED;
break;
case 1:
^.^.Label1.BgColor = $BLUE;
break;
case 2:
^.^.Label1.BgColor = $YELLOW;
break;
}
}
}
*/
}
}
PulldownItem1 << CSV ( .title, .value ){
項目1,1
項目2,2
項目3,3
};
}
Label Label1 {
X = 165;
Y = 5;
Width = 50;
Height = 20;
}
if ( !$DESIGNTIME ) {
}
}
|