兄弟前些日子做項(xiàng)目,第一次使用vb.net,碰上不少問題,相信很多初學(xué)者多多少少都會遇到這些問題,為了初學(xué)者學(xué)習(xí)方便,小弟總結(jié)了一些小經(jīng)驗(yàn),供大家參考討論。 第一篇:如何在mdi子窗體中控制父窗體的屬性等等 功能:比如打開一個(gè)子窗體后,就要設(shè)置父窗體中的某個(gè)菜單項(xiàng)或者按鈕為不可見狀態(tài),諸如此類。 內(nèi)容: mdi父窗體和mdi子窗體類定義如下: mdi父窗體: class mdiform inherits system.windows.forms.form ......... 'member mnumain friend withevents mnueditpaste as system.windows.forms.menuitem ....... 'member friend withevents toolscan as system.windows.forms.toolbarbutton private sub showchild() dim frmtmp as new mdichildfom'define a new instantce of mdichildform frmtmp.mdiparent = me 'set the new form to be a mdichild frmtmp.show() 'show the new form end sub end class mdi子窗體: class mdichildform ....... 'set mnueditpaste & toolscan cannot be seen private sub setmdimnutoolunvisible() '***************************************' ' first method you can set a menuitem to be unvisible' '***************************************' 'this method you could not control one menuitem 'you can only set a group of menuitems me.mdiparent.menu.menuitems(0).visible = false 'set the first group menuitem can not be seen 'with this method you have not right to modify toolscan
dim frmmdi as mdiform if tyhpeof me.mdiparent is mdiform frmmdi = directcast(me.mdiparent, mdiform)'get the instantce of me.mdiparent 'then you should access all the members of class mdiform without private members frmmdi.mnueditpaste = false frmmdi.toolscan = flase 'like this you could do everything with mdiform you want end if