vb.net 中MDI子窗体对其父窗体属性的获取与修改
2024-07-10 13:01:06
供稿:网友
兄弟前些日子做项目,第一次使用vb.net,碰上不少问题,相信很多初学者多多少少都会遇到这些问题,为了初学者学习方便,小弟总结了一些小经验,供大家参考讨论。
第一篇:如何在mdi子窗体中控制父窗体的属性等等
功能:比如打开一个子窗体后,就要设置父窗体中的某个菜单项或者按钮为不可见状态,诸如此类。
内容:
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
end sub
end class