Skip to content

Commit 21deac7

Browse files
committed
Settings dialog, Highlighting button issue #80
Settings dialog, update Highlighting button for issue #80
1 parent 3ed32e7 commit 21deac7

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

CSVLintNppPlugin/CsvLintNppPlugin.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121
</Compile>
122122
<Compile Include="PluginInfrastructure\DarkMode.cs" />
123123
<Compile Include="PluginInfrastructure\Lexer.cs" />
124+
<Compile Include="Tools\MenuButton.cs">
125+
<SubType>Component</SubType>
126+
</Compile>
124127
<Compile Include="Tools\Settings.cs" />
125128
<Compile Include="Tools\Helper.cs" />
126129
<Compile Include="Forms\AboutForm.cs">

CSVLintNppPlugin/PluginInfrastructure/SettingsBase.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88
using System.Windows.Forms;
99
using CSVLint.Tools;
10+
using CSVLintNppPlugin.Tools;
1011
using Kbg.NppPluginNET;
1112
using Kbg.NppPluginNET.PluginInfrastructure;
1213

@@ -150,11 +151,11 @@ private Dictionary<string, string> GetKeys(string iniFile, string category)
150151

151152
private void colorButton_Click(object sender, EventArgs e)
152153
{
153-
Button btn = (Button)sender;
154-
//ContextMenu cm = btn.ContextMenu;
155-
ContextMenuStrip cm = btn.ContextMenuStrip;
156-
157-
cm.Show(btn, new Point(0, btn.Height)); // offset from the edge of your button
154+
// Button btn = (Button)sender;
155+
// //ContextMenu cm = btn.ContextMenu;
156+
// ContextMenuStrip cm = btn.ContextMenuStrip;
157+
//
158+
// cm.Show(btn, new Point(0, btn.Height)); // offset from the edge of your button
158159
}
159160

160161
private void colorMenuItem_Click(object sender, EventArgs e)
@@ -250,16 +251,18 @@ public void ShowDialog()
250251
AutoScaleDimensions = new SizeF(6F,13F),
251252
SelectedObject = copy
252253
},
253-
new Button
254+
new MenuButton
254255
{
255256
Name = "Colors",
256-
Text = "Colors",
257+
Text = "Highlighting",
257258
Anchor = AnchorStyles.Bottom | AnchorStyles.Left,
258-
Size = new Size(75, 23),
259+
Size = new Size(100, 23),
259260
Location = new Point(13, DEFAULT_HEIGHT - 23 - 13),
260261
UseVisualStyleBackColor = true,
261262
//ContextMenu = cm
262-
ContextMenuStrip = cm
263+
Menu = cm
264+
//,Image = CSVLintNppPlugin.Properties.Resources.setcolor1,
265+
//ImageAlign = ContentAlignment.MiddleLeft
263266
}
264267
}
265268
};

CSVLintNppPlugin/Tools/MenuButton.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.ComponentModel;
2+
using System.Drawing;
3+
using System.Windows.Forms;
4+
5+
namespace CSVLintNppPlugin.Tools
6+
{
7+
/// <summary>
8+
/// MenuButton used on Settings dialog
9+
/// Based on example code by Sverrir Sigmundarson, found here https://stackoverflow.com/a/27173509/1745616
10+
/// </summary>
11+
public class MenuButton : Button
12+
{
13+
[DefaultValue(null)]
14+
public ContextMenuStrip Menu { get; set; }
15+
16+
[DefaultValue(false)]
17+
public bool ShowMenuUnderCursor { get; set; }
18+
19+
protected override void OnMouseDown(MouseEventArgs mevent)
20+
{
21+
base.OnMouseDown(mevent);
22+
23+
if (Menu != null && mevent.Button == MouseButtons.Left)
24+
{
25+
Point menuLocation;
26+
27+
if (ShowMenuUnderCursor)
28+
{
29+
menuLocation = mevent.Location;
30+
}
31+
else
32+
{
33+
menuLocation = new Point(0, Height - 1);
34+
}
35+
36+
Menu.Show(this, menuLocation);
37+
}
38+
}
39+
40+
protected override void OnPaint(PaintEventArgs pevent)
41+
{
42+
base.OnPaint(pevent);
43+
44+
if (Menu != null)
45+
{
46+
int arrowX = ClientRectangle.Width - Padding.Right - 14;
47+
int arrowY = (ClientRectangle.Height / 2) - 1;
48+
49+
Color color = Enabled ? ForeColor : SystemColors.ControlDark;
50+
using (Brush brush = new SolidBrush(color))
51+
{
52+
Point[] arrows = new Point[] { new Point(arrowX, arrowY), new Point(arrowX + 7, arrowY), new Point(arrowX + 3, arrowY + 4) };
53+
pevent.Graphics.FillPolygon(brush, arrows);
54+
}
55+
}
56+
}
57+
}
58+
}
9.5 KB
Binary file not shown.
9.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)