Cyotek.Windows.Forms.ImageBox icon indicating copy to clipboard operation
Cyotek.Windows.Forms.ImageBox copied to clipboard

[Enhancements] MouseWheelBehaviour property (zoom or scroll)?

Open HubKing opened this issue 9 years ago • 5 comments

I visited cryotek.com web site, and found that someone had asked this, and you replied that it had already been asked in GitHub. But I could not find it here, and since it seems many people want it, I hope there was a simpler way.

I mean, instead of letting each user to implement it on their own, how about adding as simple property that changes the scrolling behaviour? Like, Zoom: always zooms. Scroll: always scrolls. To zoom, use Ctrl + wheel. Auto: if the image width fits the control, but the height does not, then scrolls; otherwise, zoom.

HubKing avatar Feb 22 '17 09:02 HubKing

Hello,

Thanks for the comment. The issue you refer to was closed and so wasn't visible without searching, but it was #9

However, it's a perfectly reasonably suggestion to implement and given that you're now the third person to ask for it (and truth to tell, I could do with it in one of my core products as well), it makes perfect sense to implement it in the base control.

Assuming I don't get a PR in the next couple of days, I'll look at adding this as a core feature at the weekend.

Thanks again for the feedback!

Regards; Richard Moss

cyotek avatar Feb 22 '17 16:02 cyotek

I realize it has been a couple years since this was touched, but is there any pointers on how we could approach this? I see there is a protected property called WheelScrollsControl, but I can see no use of it in the control. I have tried to override the MouseWheel event, but I am not sure how to wire it to the ScrollControl class. This functionality is definitely needed.

bkraul avatar Nov 16 '19 15:11 bkraul

So I think I got a workaround for now. I did the following:

  • Inherit the control.
  • Expose the WheelScrollsControl property as public.
  • Override the MouseWheel event, using the WheelScrollsControl property, and execute the scroll code that is found in the base ScrollControl.cs (had to copy it). Otherwise run control's base.
        /// <summary>
        ///   Raises the <see cref="System.Windows.Forms.Control.MouseWheel" /> event.
        /// </summary>
        /// <param name="e">
        ///   A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
        /// </param>
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            if (this.WheelScrollsControl == true)
            {
                int x;
                int y;
                int delta;

                x = this.HorizontalScroll.Value;
                y = this.VerticalScroll.Value;

                // TODO: Find if we are hovering over a horizontal scrollbar and scroll that instead of the default vertical.
                if (this.VerticalScroll.Visible && this.VerticalScroll.Enabled)
                {
                    if (ModifierKeys == Keys.Control)
                    {
                        delta = this.VerticalScroll.LargeChange;
                    }
                    else
                    {
                        delta = SystemInformation.MouseWheelScrollLines * this.VerticalScroll.SmallChange;
                    }

                    y += (e.Delta > 0) ? -delta : delta;
                }
                else if (this.HorizontalScroll.Visible && this.HorizontalScroll.Enabled)
                {
                    if (ModifierKeys == Keys.Control)
                    {
                        delta = this.HorizontalScroll.LargeChange;
                    }
                    else
                    {
                        delta = SystemInformation.MouseWheelScrollLines * this.HorizontalScroll.SmallChange;
                    }

                    x += (e.Delta > 0) ? -delta : delta;
                }

                this.ScrollTo(x, y);
            }
            else
            {
                base.OnMouseWheel(e);
            }
        }

Seems to be doing the trick, and was simple enough.

bkraul avatar Nov 16 '19 15:11 bkraul

Hello,

Thanks for the comment, I'm glad you found a solution that works for you. It has been some time since I worked on this control and I've complete forgotten what state it currently in is. Despite that, it's by no means abandoned (I use it in a fair few of my projects), I just don't have time to work on this because of other commitments where users are perhaps... more vocal with their displeasure (to put it mildly).

From what I remember though, this approach won't work in the branch I'd been working on to revamp the control as the ScrollControl that the WheelScrollsControl property belongs to was removed as part of a general clean up and simplification.

I don't think I got around to adding this functionality but I do intend on adding it. No promises as I think I've broken pretty much every promise or timescale on the open source code but I'll at least dig out which branch I'm supposed to be working on and try and figure out where I am and jot down some form of plan.

Regards; Richard Moss

cyotek avatar Nov 17 '19 16:11 cyotek

@cyotek No worries. Because I merely inherited the control with just my few modifications, I am pretty sure I should be able to either revert to your updated one (when and if you choose to release) or adapt my inherited control. Thanks for the work you put into this project over the years. It is still the fastest full-featured open source image box out there. We are using the Gnostice image viewer for some use cases, and your control leaves it in the dust in terms of responsiveness and memory usage.

bkraul avatar Nov 17 '19 19:11 bkraul

I've created a pull request facing this by adding a property for the mouse wheel mode: #48

Fruchtzwerg94 avatar Oct 28 '22 11:10 Fruchtzwerg94