当前位置:网站首页>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,问题解决。
边栏推荐
- We can't tell the difference between distributed and cluster. Let's tell the story of two cooks cooking
- C#使用WinExec调用exe程序
- 全面理解Synchronized
- L2-3 is this a binary search tree- The explanation is wonderful
- AQS之ReentrantLock源码解析
- winform使用zxing生成二维码
- Use of Azkaban in task scheduler
- 指针数组、数组指针和传参的相关问题
- Serpentine filling number
- Slide the custom control to close the activity control
猜你喜欢

qgis制图

AGCTFb部分题解

IIS服务器相关错误

C#中Linq常用用法

Win32exception (0x80004005): This program is blocked by group policy. For more information, contact your system administrator.

Web vulnerability manual detection and analysis

Recyclerview universal adapter package

View CSDN blog rankings

在VMware workstation中安装WMware ESXi 6.5.0并进行配置

Ora-01950 does not have permission on tablespace
随机推荐
2020-09-18 referer authentication URL escape
Ora-01950 does not have permission on tablespace
51nod1277 maximum value in string [KMP]
2021 team programming ladder competition - Simulation Competition
BUUCTF RE-easyre
攻防世界-Re-insfsay
View CSDN blog rankings
CLR via C reading notes - loading and AppDomain
winform使用zxing生成二维码
Vmware的下载与安装(基本思路+详细过程)
Dynamic planning summary
函数指针、函数指针数组、计算器+转移表等归纳总结
Download control 1 of custom control (downloadview1)
2019.10.16 training summary
MySQL中innodb_page_cleaners详解
Installing and configuring wmware esxi 6.5.0 in VMware Workstation
查看CSDN的博客排名
QGIS mapping
Common usage of LINQ in C #
Devaxpress double click to get cell data