当前位置:网站首页>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
- Dynamic planning summary
- Talk about threads and concurrency
- Real time value transfer from C form to another form
- Simulation problem of two stacks
- Dev使用过程中的基本操作
- Call another interface button through win32API
- Web vulnerability manual detection and analysis
- Win32exception (0x80004005): This program is blocked by group policy. For more information, contact your system administrator.
- C#中IEqualityComparer接口的实现
猜你喜欢

全面理解Synchronized

October 17, 2020: question brushing 1

Basic operations during dev use

Call another interface button through win32API

Use of Azkaban in task scheduler

CLR via C reading notes - single instance application

Real time value transfer from C form to another form

AQS之BlockingQueue源码解析

打印1000~2000年之间的闰年(C语言)

区域工业互联网市场成绩单,百度智能云开物第二
随机推荐
L2-3 is this a binary search tree- The explanation is wonderful
PGP在加密技术中的应用
查看CSDN的博客排名
Installing and configuring wmware esxi 6.5.0 in VMware Workstation
Ce projet Open source est super wow, des photos manuscrites sont générées en ligne
Dev使用过程中的基本操作
AQS之BlockingQueue源码解析
DevExpress的双击获取单元格数据
全面理解MESI缓存一致性协议
2020-09-18 referer authentication URL escape
IIS服务器相关错误
Picture verification code control
Real time value transfer from C form to another form
AQS之Atomic详解
std::unique_ptr<T>与boost::scoped_ptr<T>的特殊性
Summary after the 2009 ICPC Shanghai regional competition
Reading notes of CLR via C -clr boarding and AppDomain
MySQL中update一条record的过程
September 21, 2020 referer string segmentation boost gateway code organization level
C#中IEqualityComparer接口的实现