当前位置:网站首页>C MDI open subform to remove automatically generated menu bar
C MDI open subform to remove automatically generated menu bar
2022-06-30 00:15:00 【Little brother】
C# stay DMI The menu bar is automatically generated when the subform is opened in , How to remove the menu bar ?

First open the child form in the load event of the parent form and maximize it

private void MDIParent1_Load(object sender, EventArgs e)
{
firstPage();// Open a subform
}
How to open a subform :
private void firstPage() {
splash frm = new splash();// Subform instantiation
frm.MdiParent = this;// Set the current form as the parent of the child form
frm.WindowState = FormWindowState.Maximized;// The state of the subform is maximized
frm.Show();// Display Form
}
I found a lot on the Internet , Only in use MenuStrip The menu bar can be removed , Use ToolStrip Can't remove the automatically generated menu bar , So in order to use ToolStrip Also remove the menu bar , In the parent form MenuStrip menu bar , To remove the menu bar .
First, in the ToolStrip Add MenuStrip menu bar

add to MenuStrip menu bar Of ItemAdded event

Add... To the automatically generated method
private void menuStrip1_ItemAdded_1(object sender, ToolStripItemEventArgs e)
{
if (e.Item.Text.Length == 0 // Hide subform icons
|| e.Item.Text == " To minimize the (&N)" // Hide minimize button
|| e.Item.Text == " Restore (&R)" // Hide restore button
|| e.Item.Text == " close (&C)") // Hide the close button
{
e.Item.Visible = false;
}
}
Not even after joining , You need to add this code to the parent form loading event :
this.MainMenuStrip = menuStrip1;// Set the menu bar of the child form to the menu bar of the parent form
private void MDIParent1_Load(object sender, EventArgs e)
{
this.MainMenuStrip = menuStrip1;// Set the menu bar of the child form to the menu bar of the parent form
firstPage();// Open a subform
}
When finished, generate , The menu bar is still there , But the icons are all gone :

This makes me feel twisted , How to solve it ? Thought of jumping the height of the menu bar to the minimum , However, you cannot directly adjust the height of the menu bar in the properties , So in the loading event, the height of the menu bar is changed :
Added two lines of code :
menuStrip1.AutoSize = false;
menuStrip1.Size = new Size(100, 1);
private void MDIParent1_Load(object sender, EventArgs e)
{
// Set the height of the custom menu bar to 1
menuStrip1.AutoSize = false;
menuStrip1.Size = new Size(100, 1);
this.MainMenuStrip = menuStrip1;// Set the menu bar of the child form to the menu bar of the parent form
firstPage();
}
The effect after regeneration :

stay ToolStrip above MenuStrip The menu bar has disappeared ,OK, Problem solving .
边栏推荐
- JS绘制极坐标颜色渐变
- [advanced C language] dynamic memory management
- 克隆無向圖[bfs訪問每條邊而不止節點]
- [advanced C language] string and memory function (I)
- Vulnhub靶机-MoriartyCorp
- 西门子低代码平台通过Database Connector 连接Mysql 实现增删改查
- Summary of DOM knowledge points
- FPGA Development (1) -- serial port communication
- Viewing splitchunks code segmentation from MPX resource construction optimization
- What is IGMP? What is the difference between IGMP and ICMP?
猜你喜欢

QT learning 02 GUI program example analysis

Embedded development: Hardware in the loop testing

Basic operations such as MySQL startup under Windows platform

Koa2 learning and using

How to write controller layer code gracefully?

What is IGMP? What is the difference between IGMP and ICMP?
![复制带随机指针的链表[空间换时间--hash记录]](/img/d9/d81e0e4f81174c61275e4affe0777a.png)
复制带随机指针的链表[空间换时间--hash记录]

The role of VMware virtual machine

Zhongkang holdings opens the offering: it plans to raise HK $395million net, and it is expected to be listed on July 12

基于zfoo开发项目的一些规范
随机推荐
视频ToneMapping(HDR转SDR)中的颜色空间转换问题(BT2020转BT709,YCbCr、YUV和RGB)
Basic operations such as MySQL startup under Windows platform
如何实现搜索引擎中的拼写纠错功能——思路
Official website of Greentree
Digital collection of cultural relics, opening a new way of cultural inheritance
Summary of DOM knowledge points
Preliminary syntax of JS
Vulnhub靶机-MoriartyCorp
After crossing, she said that the multiverse really exists
Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}
Viewing splitchunks code segmentation from MPX resource construction optimization
爬虫入门实战:斗鱼弹幕数据抓取,附送11节入门笔记
Summarize Flink runtime architecture in simple terms
How to view the CPU cores and threads in win11? Win11 view the tutorial of how many cores and threads the CPU is
HTAP x cloud native: tidb accelerates the release of data value and realizes data agility
Getting started with qpainter: drawing the chess interface
Siemens low code version 9.14: meet different needs
MySQL:SQL概述及数据库系统介绍 | 黑马程序员
Leetcode (680) -- verifying palindrome string II
8软件工程环境