对象.getParent()和对象._parentForm是差不多的。
对象.setParent(控件对象) 可以用于改变父窗口,比如用于全屏游戏窗口多开,或者嵌套别人的软件, 请不要用来做坏事。
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio基本控件编程演示范例";right=513;bottom=162)
winform.add(
button={cls="button";text="返回父窗口";left=330;top=18;right=492;bottom=52;z=2};
button2={cls="button";text="取主窗口句柄";left=331;top=61;right=493;bottom=95;z=3};
button3={cls="button";text="改变父窗口";left=331;top=104;right=493;bottom=138;z=7};
edit={cls="edit";text="简码编程 简码编程致力于零基础自学编程中文图解教程的分享与问答 www.jianma123.com";left=10;top=11;right=289;bottom=70;autohscroll=false;edge=1;multiline=1;vscroll=1;z=1};
groupbox={cls="groupbox";text="groupbox";left=12;top=79;right=288;bottom=137;edge=1;z=4};
radiobutton={cls="radiobutton";text="radiobutton";left=28;top=105;right=126;bottom=119;z=5};
radiobutton2={cls="radiobutton";text="radiobutton2";left=126;top=105;right=224;bottom=119;z=6}
)
/*}}*/
winform.button.oncommand = function(id,event){
//winform.msgbox( table.tostring(winform.edit._parentForm),"父窗口对象:" );
winform.msgbox( table.tostring(winform.edit.getParent()),"文本框的父窗口对象:" );
winform.msgbox( table.tostring(winform.radiobutton.getParent()),"单选框的父窗口对象:" );
}
winform.button2.oncommand = function(id,event){
winform.msgbox( winform.hwnd,"主窗口句柄为:");
}
winform.button3.oncommand = function(id,event){
winform.msgbox( table.tostring(winform.radiobutton.getParent()),"改变前单选框的父窗口对象:" );
winform.radiobutton.setParent(winform.groupbox)
winform.msgbox( table.tostring(winform.radiobutton.getParent()),"改变后单选框的父窗口对象:" );
}
winform.show()
win.loopMessage();