タブ - タブ間連携
任意のタブをアクティブにしたい
現在アクティブとなっているタブから、他の任意のタブをアクティブにするには
RootクラスのsetWindowStateメソッドと、タブ間でのメッセージ送信を行うApplicationクラスのpostInterContextMessageメソッドを利用します。
〇 処理の流れ
1.タブ間通信機能のpostInterContextMessageメソッドで任意のタブにメッセージ送信。
2.RootクラスのsetWindowStateメソッドでタブをアクティブに設定。
【サンプル実行方法】
「最初に起動するメインタブ」を「form1.crs」、「新規に起動するタブ」を「form2.crs」と
して作成し「form1.crs」から実行してください。
・最初に起動するメインタブ
Form form1 { width = 401; height = 369; //.title = "メインタブ"; /*ポートID*/ var p_id = new Array(0,1,2,3,4); append(p_id,"p_id"); Button button1 { x = 32; y = 24; width = 312; height = 48; title = "新規にタブを開く"; Function onTouch(e) { var i; for(i=0; i < ^.p_id.length; i++){ # 新しいタブを開いて、サービスIDとポートIDを一緒に引き渡す。 Application.login("form2.crs",Application.TARGET_NEWTAB,"serviceid=Sab&portid="+str( ^.p_id[i])); } root.setWindowState(WindowObject.STATE_FRONT); ^.button2.active = true; this.active = false; } } Button button2[p_id.length] { x = 32; y = 136; width = 312; height = 40; active = false; button2 [0].title = "タブ0"; button2 [1].title = "タブ1"; button2 [2].title = "タブ2"; button2 [3].title = "タブ3"; button2 [4].title = "タブ4"; Function onTouch(e) { # 新しいタブを開いて、サービスIDとポートIDを一緒に引き渡す。 var m = new Map; m["Tab"] = "openTab"; Application.postInterContextMessage( "Sab",e.from.index, m); } } Label label1 { x = 32; y = 96; width = 312; height = 32; value = "押下したボタンのタイトルに記載されているタブを表示します"; verticalAlign = ALIGN_BOTTOM; } } Function onInterContextMessage(e) { if(e.param["Tab"] == "openTab"){ # タブを選択状態にセット root.setWindowState(WindowObject.STATE_FRONT); } } if( !Application.DESIGNTIME ){ # サービスID、ポートIDをセット (セットしない場合、連携不可) Application.setCurrentContextInfo("Main","100"); }
・新規に起動するタブ
if( !Application.DESIGNTIME ){ # 起動時に受け取るサービスIDとポートID String ServiceID = Application.getProperty("serviceid"); String PortID = Application.getProperty("portid"); //.title = "タブ" + str(PortID); # サービスID、ポートIDをセット (セットしない場合、連携不可) Application.setCurrentContextInfo(ServiceID, PortID); } # タブ間メッセージ受信イベント ハンドラ Function onInterContextMessage(e) { if(e.param["Tab"] == "openTab"){ # タブを選択状態にセット root.setWindowState(WindowObject.STATE_FRONT); } } Form form2 { width = 441; height = 473; Button button1 { x = 72; y = 120; width = 256; height = 72; title = "メインタブを表示"; function onTouch(e) { var m = new Map; m["Tab"] = "openTab"; Application.postInterContextMessage( "Main",100, m); } } Label label1 { x = 56; y = 32; width = 288; height = 64; font = new Font("MS UI Gothic", 28, true); value = //.title; verticalAlign = ALIGN_MIDDLE; horizontalAlign = ALIGN_CENTER; } }
Biz-Collections Bizの宝箱 トップへ
Biz/Browser DT・Biz/Designer DT TIPS集 トップへ