選單欄[MenuStrip]
1設定完選單後,每一個子選單對應的事件中,來展示當前選單的窗體
foreach (Form f in this.MdiChildren)
{
if (f.Name == "窗體名稱")
{
return;
}
}
FrmYieldTransitEdit fyte = new FrmYieldTransitEdit();
fyte.MdiParent = this;
fyte.Show();
2以選項卡的方式開啟一個窗體
FrmYieldTransitEdit fyte = new FrmYieldTransitEdit();
//動態建立一個tabpage
TabPage tabPage1 = new TabPage();
foreach (TabPage p in tabShowSubMenu.Controls )
{
if (p.Name == "FrmYieldTransitEdit")
{
return;
}
}
tabPage1.Text = "生產運送管理";
tabPage1.Name = "FrmYieldTransitEdit";
fyte.MdiParent = this;
fyte.TopLevel = false;
//把窗體作為page新增到tabPage中
tabPage1.Controls.Add(fyte);
//新增選項卡tabPage到TabControl中
tabShowSubMenu.TabPages.Add(tabPage1);
fyte.Show();
3動態的自定義一個選項卡,把窗體加入到選項卡中
/// 把窗體作為選項卡的page
/// </summary>
/// <param name="str"></param>
/// <param name="f"></param>
public void addtabPage(string str, Form myForm)
{
//是否存在相同的,相同的就不能再次新增到選項卡中
if (tabControlCheckHave(this.tabShowSubMenu, str))
{
return;
}
else
{
tabShowSubMenu.TabPages.Add(str);
tabShowSubMenu.SelectTab(tabShowSubMenu.TabPages.Count - 1);
myForm.FormBorderStyle = FormBorderStyle.None;
myForm.Dock = DockStyle.Fill;
myForm.TopLevel = false;
if (str == "生產任務管理")
{
myForm.Show();//如果在子窗體控制了dgv預設第一行的游標效果去掉後,在這裡面最好先show然後再設定tab
myForm.Parent = tabShowSubMenu.SelectedTab;
}
}
}
/// <summary>
/// 判斷是否已經存在
/// </summary>
/// <param name="tab"></param>
/// <param name="tabName"></param>
/// <returns></returns>
public bool tabControlCheckHave(System.Windows.Forms.TabControl tab, String tabName)
{
for (int i = 0; i < tab.TabCount; i++)
{
if (tab.TabPages[i].Text == tabName)
{
tab.SelectedIndex = i;
return true;
}
}
return false;
}
private void tabShowSubMenu_DrawItem(object sender, DrawItemEventArgs e)
{
/*如果將 DrawMode 屬性設定為 OwnerDrawFixed,
則每當 TabControl 需要繪製它的一個選項卡時,它就會引發 DrawItem 事件*/
try
{
//this.tabControl1.TabPages[e.Index].BackColor = Color.LightBlue;
Rectangle tabRect = this.tabShowSubMenu.GetTabRect(e.Index);
e.Graphics.DrawString(this.tabShowSubMenu.TabPages[e.Index].Text, this.Font, SystemBrushes.ControlText, (float)(tabRect.X + 3), (float)(tabRect.Y + 3));//顯示的字型 的位置
using (Pen pen = new Pen(Color.Wheat))//x四周的顏色
{
tabRect.Offset(tabRect.Width - 15, 2);
tabRect.Width = 15;
tabRect.Height = 15;
e.Graphics.DrawRectangle(pen, tabRect);
}
Color color = (e.State == DrawItemState.Selected) ? Color.GhostWhite : Color.White;
using (Brush brush = new SolidBrush(color))
{
e.Graphics.FillRectangle(brush, tabRect);
}
using (Pen pen2 = new Pen(Color.Red))//x的顏色
{
Point point = new Point(tabRect.X + 3, tabRect.Y + 3);
Point point2 = new Point((tabRect.X + tabRect.Width) - 3, (tabRect.Y + tabRect.Height) - 3);
e.Graphics.DrawLine(pen2, point, point2);
Point point3 = new Point(tabRect.X + 3, (tabRect.Y + tabRect.Height) - 3);
Point point4 = new Point((tabRect.X + tabRect.Width) - 3, tabRect.Y + 3);
e.Graphics.DrawLine(pen2, point3, point4);
}
e.Graphics.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void tabShowSubMenu_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int x = e.X;
int y = e.Y;
Rectangle tabRect = this.tabShowSubMenu.GetTabRect(this.tabShowSubMenu.SelectedIndex);
tabRect.Offset(tabRect.Width - 0x12, 2);
tabRect.Width = 15;
tabRect.Height = 15;
if ((((x > tabRect.X) && (x < tabRect.Right)) && (y > tabRect.Y)) && (y < tabRect.Bottom))
{
this.tabShowSubMenu.TabPages.Remove(this.tabShowSubMenu.SelectedTab);
}
}
}
4在點選事件中直接呼叫
private void YieldtransitMenu_Click(object sender, EventArgs e)
{
FrmYieldTransitEdit fyte = new FrmYieldTransitEdit();
addtabPage("生產運送管理", fyte);
}
相關文章
- 工具欄選單
- 在PyQt中構建 Python 選單欄、選單和工具欄QTPython
- 選單欄快捷命令:QuickLinks for MacUIMac
- mac選單欄設定教程Mac
- PyQt5 之選單欄QT
- QuickLinks for Mac(選單欄快捷命令)UIMac
- JavaGUI——swing元件基礎(八)選單欄/選單/子選單元件JMenuBar/JMenu/JMenuItemJavaGUI元件
- CSS導航欄及下拉選單CSS
- 選單欄防休眠工具:ScreenSaverNow for MacMac
- ScreenSaverNow for Mac(選單欄防休眠工具)Mac
- win10滑鼠右鍵選單欄怎麼改 刪除右鍵選單欄無用選項的方法Win10
- 選單欄時鐘軟體:Dato for MacMac
- Bartender 3 for Mac選單欄整理軟體Mac
- HTML歷理 ICbA的側欄選單HTML
- Mac選單欄時鐘軟體:DatoMac
- Dato for Mac(選單欄時鐘軟體)Mac
- Dato for Mac選單欄時鐘軟體Mac
- TornadoFx實現側邊欄選單效果
- 多功能選單欄時鐘工具:Dato
- 流暢切換的彩色選單欄:ColorfulNavigationBarNavigation
- 純CSS打造淘寶導航選單欄CSS
- 系統選單欄網路工具:Airtool for MacAIMac
- Bartender 3 for Mac選單欄管理工具Mac
- JavaScript側欄緩動分享選單詳解JavaScript
- Stats for mac - 選單欄系統監視器Mac
- Bartender for Mac(選單欄應用圖示管理)Mac
- pycharm 選單欄不見了怎麼辦PyCharm
- Moment for Mac(選單欄倒數日應用)Mac
- Moment for Mac選單欄倒數日應用Mac
- Airtool for Mac系統選單欄網路工具AIMac
- start11,自定義win11的選單欄和桌面欄工具
- Bartender 5 for Mac:選單欄圖示管理軟體Mac
- mac選單欄語言翻譯工具:Linguist for MacMacNGUI
- 選單欄日曆提醒工具:Calendar 366 II for MacMac
- mac選單欄不顯示了,如何設定?Mac
- 管理Mac電腦選單欄中的圖示Mac
- Mac選單欄應用管理軟體:Bartender 4Mac
- 選單欄應用管理軟體-Bartender 4 MacMac
- 關於macOS 選單欄的隱藏操作技巧Mac