-
Notifications
You must be signed in to change notification settings - Fork 4
/
ModifiedMenuItem.cs
58 lines (54 loc) · 1.79 KB
/
ModifiedMenuItem.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using Echoes;
namespace ModifiedControls
{
public class ModifiedMenuItem : MenuItem
{
public float fontSize = 10f;
public ModifiedMenuItem(string text)
: base(text)
{
Init();
}
public ModifiedMenuItem()
: base()
{
Init();
}
void Init()
{
this.OwnerDraw = true;
this.DrawItem += ModifiedMenuItem_DrawItem;
this.MeasureItem += ModifiedMenuItem_MeasureItem;
}
void ModifiedMenuItem_MeasureItem(object sender, MeasureItemEventArgs e)
{
MenuItem m = (MenuItem)sender;
Font font = new Font(Program.mainWindow.font1.FontFamily, fontSize);
SizeF sze = e.Graphics.MeasureString(m.Text, font);
e.ItemHeight = (int)sze.Height;
e.ItemWidth = (int)sze.Width;
}
void ModifiedMenuItem_DrawItem(object sender, DrawItemEventArgs e)
{
MenuItem cmb = sender as MenuItem;
e.DrawBackground();
Color c1 = Program.mainWindow.controlBackColor;
Color c2 = Program.mainWindow.controlForeColor;
if (e.State != DrawItemState.NoAccelerator)
{
c1 = Program.mainWindow.controlForeColor;
c2 = Program.mainWindow.controlBackColor;
}
e.Graphics.FillRectangle(new SolidBrush(c1), e.Bounds);
e.Graphics.DrawString(Text, new Font(Program.mainWindow.font1.FontFamily, fontSize), new SolidBrush(c2), e.Bounds);
Console.Write(e.State.ToString() + "|");
}
}
}