0

thanks to http://www.eqqon.com/index.php/Piccolo_Snippets, i had mousewheel zooming working well until i added winform widgets to the form outside of the canvas; see pic of a test form below:

form with a piccolo canvas and winform button and trackbar

i found that if i clicked on button1, and moused back onto the canvas, i no longer get mousewheel events. Other mouse events (e.g. PNode entry/leave) still work however. even after clicking on the canvas, the mousewheel is still dead. the canvas's mousedown event works fine also. so only the mousewheel breaks. below is minimalist code to demonstrate what i'm seeing.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using UMD.HCIL.Piccolo;
using UMD.HCIL.Piccolo.Event;
using UMD.HCIL.Piccolo.Nodes;

namespace piccolo_wheel_test {
    public partial class Form1 : Form {

        int mdown_count = 0;
        int mwheel_count = 0;

        public Form1() {
            InitializeComponent();

            PNode rect = PPath.CreateRectangle(40, 40, 20, 50);
            rect.Brush = Brushes.Blue;
            pCanvas1.Layer.AddChild(rect);

            pCanvas1.Camera.MouseWheel += new PInputEventHandler(Camera_MouseWheel);
            pCanvas1.Camera.MouseDown += new PInputEventHandler(Camera_MouseDown);
        }

        void Camera_MouseWheel(object sender, PInputEventArgs e) {
            Debug.WriteLine("got mouse wheel: " + (mwheel_count++).ToString());
        }

        void Camera_MouseDown(object sender, PInputEventArgs e) {
            Debug.WriteLine("got mouse down: " + (mdown_count++).ToString());
        }

        private void pCanvas1_Enter(object sender, EventArgs e) {
            Debug.WriteLine("enter pcanvas");
        }

        private void pCanvas1_Leave(object sender, EventArgs e) {
            Debug.WriteLine("leave pcanvas");
        }

        private void button1_Enter(object sender, EventArgs e) {
            Debug.WriteLine("enter button");
        }

        private void button1_Leave(object sender, EventArgs e) {
            Debug.WriteLine("leave button");
        }

    }
}

as an aside, i see that the canvas does not raise "enter"/"leave" events consistently; i see one "enter" when the form loads and one "leave" if i click button1 but no more "enter"/"leave" if i go back and forth. further, when i click on button1, i raises its "enter" event but when i click back on the canvas, "button1" doesn't raise its "leave" event (which it does if i clicked on other winform widgets, such as the trackbar.) thanks.

4mla1fn
  • 169
  • 1
  • 15
  • Only the active/focused control gets events. When you click on something else, it becomes the active control. You can override WndProc to redirect wheel events to the control that the mouse is over (there are also utils that do this globally for Windows). – Ňɏssa Pøngjǣrdenlarp May 23 '16 at 12:30
  • See [this](http://stackoverflow.com/a/4431657/1997232). Creating a focusable control is a better way (more distinct for the user) to deal with mouse wheel conflicts (when others accepting mouse wheel too, e.g. `TrackBar`). As for `Button` you can simply make it participating in zooming logic (by subscribing to mouse wheel events and calling common method), so your control can be zoomed while `Button` has focus and use uses mouse wheel. – Sinatr May 23 '16 at 12:50
  • 1
    You don't have Windows 10 yet, the MouseWheel event is raised on the control with the focus. Clearly that pCanvas1 control has trouble dealing with focus when you can't get the Enter event to get raised again. So sure, no MouseWheel event either. A possible workaround is to add the MouseDown event for pCanvas1 and call pCanvas1.Focus(). Do make sure that the user can *see* it has the focus, you may have to add the Paint event as well and draw a focus rectangle. – Hans Passant May 23 '16 at 13:03
  • many thanks all for the comments. so there seems to be some inconsistent behavior with this library regarding focus. as another example, i'm now using mousemove() to show the cursor coordinates. this event is consistently raised after a click on button1 without any explicit call to set the focus. in any case, as suggested by hans, i've put the following in my mousemove() method:`if (!pCanvas1.ContainsFocus) { pCanvas1.Focus(); }` this seems to work nicely so far. (how do i mark the question as answered with credit to hans?) – 4mla1fn May 24 '16 at 20:38

0 Answers0