当前位置:网站首页>C#MDI打开子窗体去掉自动生成的菜单栏
C#MDI打开子窗体去掉自动生成的菜单栏
2022-06-29 09:28:00 【小哥丷】
C#在DMI中打开子窗体时自动生成了菜单栏,怎么去掉菜单栏呢呢?

先在父窗体的加载事件中打开子窗体并使它最大化

private void MDIParent1_Load(object sender, EventArgs e)
{
firstPage();//打开子窗体
}
打开子窗体的方法:
private void firstPage() {
splash frm = new splash();//子窗体实例化
frm.MdiParent = this;//设置当前窗体为子窗体的父窗体
frm.WindowState = FormWindowState.Maximized;//子窗体的状态是最大化
frm.Show();//显示窗体
}
在网上找了好多发现,只有在使用MenuStrip菜单栏的时候才能去掉,使用ToolStrip的时候无法去掉自动生成的菜单栏,所以为了使用ToolStrip的时候也去掉菜单栏,就在父窗体中一并加入了MenuStrip菜单栏,来实现去掉菜单栏。
首先在ToolStrip上面加入MenuStrip菜单栏

添加MenuStrip菜单栏的ItemAdded事件

在自动生成的方法中加入
private void menuStrip1_ItemAdded_1(object sender, ToolStripItemEventArgs e)
{
if (e.Item.Text.Length == 0 //隐藏子窗体图标
|| e.Item.Text == "最小化(&N)" //隐藏最小化按钮
|| e.Item.Text == "还原(&R)" //隐藏还原按钮
|| e.Item.Text == "关闭(&C)") //隐藏关闭按钮
{
e.Item.Visible = false;
}
}
加入之后还不行,需要在父窗体加载事件中加入这句代码:
this.MainMenuStrip = menuStrip1;//把子窗体菜单栏设置给父窗体的菜单栏
private void MDIParent1_Load(object sender, EventArgs e)
{
this.MainMenuStrip = menuStrip1;//把子窗体菜单栏设置给父窗体的菜单栏
firstPage();//打开子窗体
}
完成之后生成,发现菜单栏还在,但是图标全没了:

这样看觉得好变扭,怎么解决呢?想到了把菜单栏的高度跳到最小就行了,但是属性中不能直接调整菜单栏高度,于是在加载事件中做了改变菜单栏高度的操作:
加入了两句代码:
menuStrip1.AutoSize = false;
menuStrip1.Size = new Size(100, 1);
private void MDIParent1_Load(object sender, EventArgs e)
{
//设置自定义菜单栏的高度为1
menuStrip1.AutoSize = false;
menuStrip1.Size = new Size(100, 1);
this.MainMenuStrip = menuStrip1;//把子窗体菜单栏设置给父窗体的菜单栏
firstPage();
}
再次生成之后的效果:

在ToolStrip上面的MenuStrip菜单栏已经不见了,OK,问题解决。
边栏推荐
- Devaxpress double click to get cell data
- 如何快速完成磁盘分区
- 2019.11.17 training summary
- Beautiful ruins around Kiev -- a safe guide to Chernobyl!
- InnoDB in MySQL_ page_ Cleaners details
- QGIS mapping
- 1147 heaps (30 points)
- 产品力不输比亚迪,吉利帝豪L雷神Hi·X首月交付1万台
- Analysis on the specific execution process of an insert statement in MySQL 8.0 (3)
- Seaweedfs security configuration
猜你喜欢
随机推荐
在实践中学习Spark计算框架(01)
2019.11.17 training summary
October 17, 2020: question brushing 1
C语言库函数--strstr()
1146 topological order (25 points)
Recurrence of vulnerability analysis for Cisco ASA, FTD and hyperflex HX
AGCTFb部分题解
std::unique_ PTR < T> and boost:: scoped_ Particularity of PTR < t >
Win32exception (0x80004005): This program is blocked by group policy. For more information, contact your system administrator.
区域工业互联网市场成绩单,百度智能云开物第二
2019.10.6 training summary
HDU 4578 transformation (segment tree + skillful lazy tag placement)
BUUCTF RE-easyre
《CLR via C#》读书笔记-单实例应用程序
Picture verification code control
Basic operations during dev use
Ora-01950 does not have permission on tablespace
Ce projet Open source est super wow, des photos manuscrites sont générées en ligne
Is it safe to open a stock account with the QR code given by the manager of a securities firm? I want to open an account
Contents of advanced mathematics









