vb.net 中MDI子窗体对其父窗体属性的获取与修改

本文分享了VB.NET编程中MDI窗体的实用技巧,特别关注如何从子窗体控制父窗体的菜单项及按钮可见性等属性。通过示例代码介绍了实现这些功能的具体步骤。

兄弟前些日子做项目,第一次使用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

 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值