当前位置:网站首页>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 .
边栏推荐
- Web APIs 环境对象 丨黑马程序员
- modelsim的TCL脚本的define incdir命令解析
- Summary of DOM knowledge points
- QT learning 06 widgets and window types
- vsftp 与 TFTP 与 samba 与 nfs 复习
- Binary search tree 230 The element with the smallest K in the binary search tree 1038 From binary search tree to larger sum tree
- Project 1: deploy lamp ECSHOP e-commerce platform
- Solr基础操作14
- This PMP Exam (June 25), some people are happy and others are worried. That's why
- [rust weekly library] Tokei - a utility for statistics of code lines and other information
猜你喜欢

Basic tutorial for installing monggodb in win10
![[advanced C language] special user-defined type](/img/f3/c01b8b10e02860afc88a216ff8dbce.png)
[advanced C language] special user-defined type

Basic operations such as MySQL startup under Windows platform

QT learning 01 GUI program principle analysis

Zhongkang holdings opens the offering: it plans to raise HK $395million net, and it is expected to be listed on July 12
![[advanced C language] user defined type](/img/0d/50924ef21f07ca8188855c2b78d929.png)
[advanced C language] user defined type

EB-5 immigration in the United States reappears to be positive, and the reauthorization policy of the regional center is suspended

西门子低代码平台通过Database Connector 连接Mysql 实现增删改查

Activity invitation | the Apache Doris community essay and speech solicitation activity has begun!

JVM之栈空间
随机推荐
Project 1: deploy lamp ECSHOP e-commerce platform
gyctf_2020_document
This PMP Exam (June 25), some people are happy and others are worried. That's why
由GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}引起的刨根问底
Leetcode (76) -- Minimum Covering substring
Vulnhub target -moriartycorp
Koa2 learning and using
Activity invitation | the Apache Doris community essay and speech solicitation activity has begun!
8软件工程环境
【UITableView】坑一:tableView:heightForHeaderInSection:方法不执行
Analysis of common vlog parameters
代码分析平台 SonarQube 实战
[advanced C language] user defined type
【毕业季|进击的技术er】工作七年的职场人,不希望你们再走弯路
TP5查询AND和OR条件嵌套
Summary of DOM knowledge points
Exploration and Practice on the future direction of byte cloud database
Solr基础操作9
QT learning 01 GUI program principle analysis
复制带随机指针的链表[空间换时间--hash记录]