-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainForm.Menu.cs
More file actions
79 lines (63 loc) · 2.95 KB
/
Copy pathMainForm.Menu.cs
File metadata and controls
79 lines (63 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace CMDownloaderUI
{
// This file only adds the menu to the existing MainForm via partial class.
internal sealed partial class MainForm
{
private MenuStrip _menu;
private ToolStripMenuItem _miFile, _miSettings, _miAbout;
private ToolStripMenuItem _miLock, _miOpenOnDone, _miAdblock, _miParallel;
private ToolStripMenuItem _miNv, _miVid;
private TableLayoutPanel _headerBar;
private Label _brand; // used only if we don't find your existing brand label
// host we align the menu to (your top toolbar)
private Control? _toolbar;
// Build and attach the app menu (call this once from the MainForm ctor, after pnlTop/pnlMain exist)
private void BuildMenu(Control hostToolbar)
{
// Avoid duplicate menus
if (_menu != null && !_menu.IsDisposed && Controls.Contains(_menu))
return;
_toolbar = hostToolbar;
_menu = new MenuStrip
{
// IMPORTANT: do NOT dock; we will position it manually beside the brand
Dock = DockStyle.None,
GripStyle = ToolStripGripStyle.Hidden,
Renderer = new ToolStripProfessionalRenderer(),
Padding = new Padding(2, 0, 2, 0),
Margin = new Padding(0),
BackColor = Color.Transparent
};
// top-level items
_miFile = new ToolStripMenuItem("&File");
_miSettings = new ToolStripMenuItem("&Settings");
_miAbout = new ToolStripMenuItem("&About");
_menu.Items.AddRange(new ToolStripItem[] { _miFile, _miSettings, _miAbout });
// Put the menu on the same parent as the brand overlay (the Form itself)
if (_menu.Parent != this)
this.Controls.Add(_menu);
// Anchor to the right so it stays flush-right when resizing
_menu.Anchor = AnchorStyles.Top | AnchorStyles.Right;
// initial placement + keep it in place on resize/relayout
PositionMenu();
this.Resize += (_, __) => PositionMenu();
_toolbar.Resize += (_, __) => PositionMenu();
_toolbar.LocationChanged += (_, __) => PositionMenu();
// If you already build your Settings submenu here, keep that code below this point.
}
private void PositionMenu()
{
if (_menu == null || _menu.IsDisposed || _toolbar == null) return;
// align with the toolbar’s top edge; tweak the +4 as needed to match your brand’s baseline
int y = _toolbar.Top + 4;
// flush-right with an 8px inset
int x = this.ClientSize.Width - _menu.PreferredSize.Width - 8;
_menu.Location = new Point(Math.Max(8, x), y);
_menu.BringToFront();
}
}
}