当前位置:网站首页>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 .
边栏推荐
- Solr basic operations 13
- Unity about failure (delay) of destroy and ondestroy
- Events in JS
- 克隆无向图[bfs访问每条边而不止节点]
- 数据中台的五个关键要素
- 剑指 Offer II 037. 小行星碰撞
- 爬虫入门实战:斗鱼弹幕数据抓取,附送11节入门笔记
- [advanced C language] dynamic memory management
- Zhongkang holdings opens the offering: it plans to raise HK $395million net, and it is expected to be listed on July 12
- Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}
猜你喜欢
![[advanced C language] string and memory function (I)](/img/fa/5531253940d99f2646cb6964992e7c.png)
[advanced C language] string and memory function (I)

Andorid source build/envsetup. SH details to know

Construction of module 5 of actual combat Battalion

QT learning 06 widgets and window types

8 software engineering environment

Leetcode (680) -- verifying palindrome string II

Serialization of binary tree 297 Serialization and deserialization of binary tree 652 Find duplicate subtrees

Embedded development: Hardware in the loop testing

Vulnhub靶机-MoriartyCorp

Basic tutorial for installing monggodb in win10
随机推荐
Mysql:sql overview and database system introduction | dark horse programmer
Stack space of JVM
8软件工程环境
Review of vsftp, TFTP, samba and NFS
JVM之栈空间
Analysis of common vlog parameters
Solr基础操作16
Golang6 reflection
Machine learning: the concept and application of VC dimension
QT learning 02 GUI program example analysis
About mongodb error: connecting to: mongodb://127.0.0.1:27017/?compressors=disabled &gssapiServiceName=mongodb
Copy linked list with random pointer [space for time --hash record]
Fine grained identification, classification, retrieval data set collation
vsftp 与 TFTP 与 samba 与 nfs 复习
Solr基础操作13
label问题排查:打不开标注好的图像
After 8 years of polishing, "dream factory of game design" released an epic update!
由GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}引起的刨根问底
如何实现搜索引擎中的拼写纠错功能——思路
Exploration and Practice on the future direction of byte cloud database