-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScrollPanel.cs
More file actions
73 lines (65 loc) · 2.07 KB
/
Copy pathScrollPanel.cs
File metadata and controls
73 lines (65 loc) · 2.07 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace printPoster
{
public partial class ScrollPanel : Panel
{
public ScrollPanel()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
}
public event ZoomEventHandler ZoomEvent;
// based on http://stackoverflow.com/questions/7828121/shift-mouse-wheel-horizontal-scrolling/11218920#11218920
protected override void OnMouseWheel(MouseEventArgs e)
{
if (ModifierKeys == Keys.Control)
{
if (e != null)
{
var scrolledPos = e.Location;
var pos = AutoScrollPosition;
scrolledPos.Offset(-pos.X, -pos.Y);
OnZoomEvent(new ZoomEventArgs(scrolledPos, e.Delta / 120));
}
return;
}
else if (ModifierKeys == Keys.Shift && HScroll && VScroll)
{
VScroll = false;
base.OnMouseWheel(e);
VScroll = true;
}
else
base.OnMouseWheel(e);
}
protected void OnZoomEvent(ZoomEventArgs e)
{
ZoomEvent(this, e);
}
protected override void OnScroll(ScrollEventArgs se)
{
base.OnScroll(se);
var hs = HorizontalScroll;
}
public class ZoomEventArgs : EventArgs
{
public int Delta { get; private set; }
public Point Location { get; private set; }
public ZoomEventArgs(Point location, int delta)
{
Delta = delta;
Location = location;
}
}
public delegate void ZoomEventHandler(object sender, ZoomEventArgs e);
}
}