Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit cb41be6

Browse files
committed
Update 参考图菜单增加鼠标滚动
1 parent f6ae7bd commit cb41be6

File tree

7 files changed

+212
-29
lines changed

7 files changed

+212
-29
lines changed

AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[assembly: System.Runtime.InteropServices.ComVisible(false)]
88
[assembly: System.Runtime.InteropServices.Guid("4483e561-8b3e-427d-98a4-e0e821b7bf2f")]
99
[assembly: System.Reflection.AssemblyConfiguration("")]
10-
[assembly: System.Reflection.AssemblyFileVersion("2.5.7")]
10+
[assembly: System.Reflection.AssemblyFileVersion("2.5.8")]
1111
[assembly: System.Runtime.CompilerServices.CompilationRelaxations(8)]
1212
[assembly: System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows = true)]
1313

SETUNA.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@
6262
<PropertyGroup>
6363
<StartupObject>Program</StartupObject>
6464
</PropertyGroup>
65+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
66+
<DebugSymbols>true</DebugSymbols>
67+
<OutputPath>bin\x64\Debug\</OutputPath>
68+
<DefineConstants>DEBUG;TRACE</DefineConstants>
69+
<DebugType>full</DebugType>
70+
<PlatformTarget>x64</PlatformTarget>
71+
<LangVersion>7.3</LangVersion>
72+
<ErrorReport>prompt</ErrorReport>
73+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
74+
</PropertyGroup>
75+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
76+
<OutputPath>bin\x64\Release\</OutputPath>
77+
<DefineConstants>TRACE</DefineConstants>
78+
<Optimize>true</Optimize>
79+
<DebugType>pdbonly</DebugType>
80+
<PlatformTarget>x64</PlatformTarget>
81+
<LangVersion>7.3</LangVersion>
82+
<ErrorReport>prompt</ErrorReport>
83+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
84+
</PropertyGroup>
6585
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
6686
<ItemGroup>
6787
<Compile Include="Properties\Image.Designer.cs">
@@ -301,13 +321,15 @@
301321
<Compile Include="SETUNA\Main\ToolStripDustboxList.cs">
302322
<SubType>Component</SubType>
303323
</Compile>
324+
<Compile Include="SETUNA\Main\ToolStripEx.cs" />
304325
<Compile Include="SETUNA\Main\ToolStripScrapList.cs">
305326
<SubType>Component</SubType>
306327
</Compile>
307328
<Compile Include="SETUNA\Main\ToolStripStyleButton.cs">
308329
<SubType>Component</SubType>
309330
</Compile>
310331
<Compile Include="Program.cs" />
332+
<Reference Include="System.Data" />
311333
<Reference Include="System.Windows.Forms" />
312334
<Reference Include="System" />
313335
<Reference Include="System.Drawing" />

SETUNA.sln

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.329
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29613.14
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SETUNA", "SETUNA.csproj", "{F50B9DA0-2DEA-464A-B568-888E54701D07}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
1011
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
1113
Release|x86 = Release|x86
1214
EndGlobalSection
1315
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Debug|x64.ActiveCfg = Debug|x64
17+
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Debug|x64.Build.0 = Debug|x64
1418
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Debug|x86.ActiveCfg = Debug|x86
1519
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Debug|x86.Build.0 = Debug|x86
20+
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Release|x64.ActiveCfg = Release|x64
21+
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Release|x64.Build.0 = Release|x64
1622
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Release|x86.ActiveCfg = Release|x86
1723
{F50B9DA0-2DEA-464A-B568-888E54701D07}.Release|x86.Build.0 = Release|x86
1824
EndGlobalSection

SETUNA/Main/ToolStripAbstractList.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace SETUNA.Main
22
{
3+
using Opulos.Core.UI;
34
using System;
45
using System.Collections;
56
using System.Windows.Forms;
@@ -14,6 +15,8 @@ public ToolStripAbstractList(string text, ScrapBook scrapbook) : base(text)
1415
this._scrapbook = scrapbook;
1516
base.DropDownItems.Clear();
1617
base.DropDownItems.Insert(0, new ToolStripMenuItem("无"));
18+
19+
ToolStripEx.BigButtons(this.DropDown);
1720
}
1821

1922
protected abstract ArrayList GetItems();
@@ -22,8 +25,25 @@ protected virtual void OnAddItem(ToolStripMenuItem addmi)
2225
{
2326
}
2427

28+
protected override void OnDropDownOpened(EventArgs e)
29+
{
30+
Mainform.instance.MouseWheelCallbackEvent += DropDown_MouseWheel;
31+
this.DropDown.MouseWheel += DropDown_MouseWheel;
32+
33+
base.OnDropDownOpened(e);
34+
}
35+
36+
private void DropDown_MouseWheel(object sender, MouseEventArgs e)
37+
{
38+
if (e.Delta > 0) SendKeys.SendWait("{UP}");
39+
else SendKeys.SendWait("{DOWN}");
40+
}
41+
2542
protected override void OnDropDownClosed(EventArgs e)
2643
{
44+
this.DropDown.MouseWheel -= DropDown_MouseWheel;
45+
Mainform.instance.MouseWheelCallbackEvent -= DropDown_MouseWheel;
46+
2747
this._createdlist = false;
2848
base.OnDropDownClosed(e);
2949
}
@@ -43,7 +63,8 @@ protected void RefreshList()
4363
{
4464
foreach (ScrapBase base2 in this.GetItems())
4565
{
46-
ToolStripMenuItem addmi = new ToolStripMenuItem(string.Concat(new object[] { base2.Name, "\n", base2.Width, " x ", base2.Height }), base2.GetThumbnail(), new EventHandler(this._scrapbook.BindForm.OnActiveScrapInList)) {
66+
ToolStripMenuItem addmi = new ToolStripMenuItem(string.Concat(new object[] { base2.Name, "\n", base2.Width, " x ", base2.Height }), base2.GetThumbnail(), new EventHandler(this._scrapbook.BindForm.OnActiveScrapInList))
67+
{
4768
Tag = base2,
4869
ImageScaling = ToolStripItemImageScaling.None
4970
};

SETUNA/Main/ToolStripEx.cs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Drawing;
5+
using System.Runtime.InteropServices;
6+
using System.Windows.Forms;
7+
8+
namespace Opulos.Core.UI
9+
{
10+
//https://stackoverflow.com/questions/29083903/contextmenustrip-scroll-up-or-down-button
11+
///<summary>Extension class to increase the size of the scroll up-down arrows on a drop down context menu or tool strip menu. The default up-down arrows are only 5 pixels high.</summary>
12+
public static class ToolStripEx
13+
{
14+
public delegate void Action();
15+
private static Hashtable htData = new Hashtable();
16+
17+
private class Data
18+
{
19+
public bool needsUpdate = true;
20+
public bool disposeLastImage = false;
21+
public ToolStrip toolStrip = null;
22+
public List<Image> currentImages = new List<Image>();
23+
}
24+
25+
public static void BigButtons(ToolStrip toolStrip)
26+
{
27+
htData[toolStrip] = new Data() { toolStrip = toolStrip };
28+
toolStrip.VisibleChanged += toolStrip_VisibleChanged;
29+
toolStrip.ForeColorChanged += toolStrip_ForeColorChanged;
30+
toolStrip.Disposed += toolStrip_Disposed;
31+
}
32+
33+
static void toolStrip_Disposed(object sender, EventArgs e)
34+
{
35+
Data d = (Data)htData[sender];
36+
if (d != null && d.currentImages != null)
37+
{
38+
foreach (var img in d.currentImages)
39+
img.Dispose();
40+
d.currentImages = null;
41+
htData.Remove(sender);
42+
}
43+
}
44+
45+
static void toolStrip_ForeColorChanged(object sender, EventArgs e)
46+
{
47+
Data d = (Data)htData[sender];
48+
d.needsUpdate = true;
49+
UpdateImages(d);
50+
}
51+
52+
static void toolStrip_VisibleChanged(object sender, EventArgs e)
53+
{
54+
Data d = (Data)htData[sender];
55+
UpdateImages(d);
56+
}
57+
58+
private static void UpdateImages(Data d)
59+
{
60+
if (!d.needsUpdate)
61+
return;
62+
63+
Action a = () =>
64+
{
65+
try
66+
{
67+
var list = GetChildWindows(d.toolStrip.Handle);
68+
if (list.Count == 0)
69+
return;
70+
71+
List<Image> newImages = new List<Image>();
72+
int k = 0;
73+
74+
foreach (var i in list)
75+
{
76+
var c = Control.FromHandle(i) as Label;
77+
if (c != null && d.needsUpdate)
78+
{
79+
String glyph = (k == 0 ? "t" : "u");
80+
using (Font f = new System.Drawing.Font("Marlett", 20f))
81+
{
82+
Size s = TextRenderer.MeasureText("t", f);
83+
var oldImage = c.Image;
84+
c.Image = new Bitmap(s.Width, s.Height);
85+
newImages.Add(c.Image);
86+
// avoid disposing the default image
87+
// might cause problems, not sure
88+
if (d.disposeLastImage)
89+
oldImage.Dispose();
90+
using (Graphics g = Graphics.FromImage(c.Image))
91+
{
92+
using (Brush b = new SolidBrush(d.toolStrip.ForeColor))
93+
g.DrawString(glyph, f, b, 0, 0);
94+
}
95+
c.AutoSize = true;
96+
}
97+
k++;
98+
}
99+
}
100+
if (newImages.Count > 0)
101+
{
102+
d.needsUpdate = false;
103+
d.disposeLastImage = true;
104+
d.currentImages = newImages;
105+
}
106+
}
107+
catch { } // protect against crash (just in case)
108+
};
109+
110+
d.toolStrip.BeginInvoke(a);
111+
}
112+
113+
private static List<IntPtr> GetChildWindows(IntPtr parent)
114+
{
115+
List<IntPtr> result = new List<IntPtr>();
116+
GCHandle listHandle = GCHandle.Alloc(result);
117+
try
118+
{
119+
EnumChildWindows(parent, enumProc, GCHandle.ToIntPtr(listHandle));
120+
}
121+
finally
122+
{
123+
if (listHandle.IsAllocated)
124+
listHandle.Free();
125+
}
126+
return result;
127+
}
128+
129+
private delegate bool EnumChildProc(IntPtr hWnd, IntPtr lParam);
130+
private static EnumChildProc enumProc = new EnumChildProc(CallChildEnumProc);
131+
private static bool CallChildEnumProc(IntPtr hWnd, IntPtr lParam)
132+
{
133+
GCHandle gch = GCHandle.FromIntPtr(lParam);
134+
List<IntPtr> list = gch.Target as List<IntPtr>;
135+
if (list == null)
136+
throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");
137+
138+
list.Add(hWnd);
139+
return true;
140+
}
141+
142+
[DllImport("user32.dll")]
143+
private static extern bool EnumChildWindows(IntPtr hWndParent, EnumChildProc lpEnumFunc, IntPtr lParam);
144+
}
145+
}

SETUNA/Mainform.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ static public Mainform instance
4848
private NotifyIcon setunaIcon;
4949
private SETUNA.Main.ContextStyleMenuStrip setunaIconMenu;
5050
private SETUNA.Main.ContextStyleMenuStrip subMenu;
51-
private ToolStripMenuItem testToolStripMenuItem;
5251
private Timer timPool;
5352
private Button button4;
5453
private Button button1;
5554
private Timer timer1;
56-
private ToolTip toolTip1;
55+
56+
public delegate void MouseWheelCallback(object sender, MouseEventArgs e);
57+
public event MouseWheelCallback MouseWheelCallbackEvent;
5758

5859
public Mainform()
5960
{
@@ -356,12 +357,9 @@ private void InitializeComponent()
356357
this.setunaIcon = new System.Windows.Forms.NotifyIcon(this.components);
357358
this.setunaIconMenu = new SETUNA.Main.ContextStyleMenuStrip(this.components);
358359
this.subMenu = new SETUNA.Main.ContextStyleMenuStrip(this.components);
359-
this.testToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
360-
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
361360
this.button4 = new System.Windows.Forms.Button();
362361
this.button1 = new System.Windows.Forms.Button();
363362
this.timer1 = new System.Windows.Forms.Timer(this.components);
364-
this.subMenu.SuspendLayout();
365363
this.SuspendLayout();
366364
//
367365
// timPool
@@ -387,25 +385,9 @@ private void InitializeComponent()
387385
// subMenu
388386
//
389387
this.subMenu.ImageScalingSize = new System.Drawing.Size(36, 36);
390-
this.subMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
391-
this.testToolStripMenuItem});
392388
this.subMenu.Name = "subMenu";
393389
this.subMenu.Scrap = null;
394-
this.subMenu.Size = new System.Drawing.Size(123, 38);
395-
//
396-
// testToolStripMenuItem
397-
//
398-
this.testToolStripMenuItem.Name = "testToolStripMenuItem";
399-
this.testToolStripMenuItem.Size = new System.Drawing.Size(122, 34);
400-
this.testToolStripMenuItem.Text = "test";
401-
//
402-
// toolTip1
403-
//
404-
this.toolTip1.IsBalloon = true;
405-
this.toolTip1.ShowAlways = true;
406-
this.toolTip1.StripAmpersands = true;
407-
this.toolTip1.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
408-
this.toolTip1.ToolTipTitle = "asfdadsf";
390+
this.subMenu.Size = new System.Drawing.Size(61, 4);
409391
//
410392
// button4
411393
//
@@ -778,6 +760,16 @@ public void ScrapMenuOpening(object sender, ScrapMenuArgs e)
778760
{
779761
this.subMenu.Scrap = e.scrap;
780762
this.subMenu.Show(e.scrap, e.scrap.PointToClient(Cursor.Position));
763+
this.subMenu.MouseWheel -= SubMenu_MouseWheel;
764+
this.subMenu.MouseWheel += SubMenu_MouseWheel;
765+
}
766+
767+
private void SubMenu_MouseWheel(object sender, MouseEventArgs e)
768+
{
769+
if(MouseWheelCallbackEvent != null)
770+
{
771+
MouseWheelCallbackEvent(sender, e);
772+
}
781773
}
782774

783775
public void ScrapRemoved(object sender, ScrapEventArgs e)

SETUNA/Mainform.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,6 @@
386386
<metadata name="subMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
387387
<value>698, 17</value>
388388
</metadata>
389-
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
390-
<value>879, 17</value>
391-
</metadata>
392389
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
393390
<value>1248, 17</value>
394391
</metadata>

0 commit comments

Comments
 (0)