Mousewheel needs to scroll user control

I have a usercontrol that I created. I added a panel and a vertical scroll bar to the right of it. I would like to scroll it with the mouse. The problem is that there seem to be no events that fire on the mouse wheels. If I remove the panel, then the user control will have focus, and it will shoot on the mouse wheel in the form. But with the panel on it, the mouse event in the panel panel, or user control inside the control or even in the form, does not seem to fire. The best solution would be to fire an event in usercontrol, but I would even accept an event in the form and return it to usercontrol.

I use vb.net and vs2005 if that matters.

+3
source share
5 answers

I have been doing this all day, maybe I figured it out. The mousewheel event is dispatched only with focus control. The panel cannot have focus. Since the panel closes the usercontrol, it also cannot get focus. (unless it's the only control on the form) If I call me.focus on the mouseenter event panel, it sets focus to usercontrol, allowing it to accept the mouse event. The event is triggered in form and in control. I am still open to suggestions if there is a better way, although this seems a bit hacky.

+2
source

, . , .

, .

+3
  • VB.NET Winforms
  • Panel
  • "" "true".
  • For i As Integer = 1 To 100
        Dim b As New Button()
        b.Text = i.ToString()
        b.Size = New Size(60, 40)
        b.Location = New Point(0, (i * b.Height) - b.Height)
        b.Parent = Panel1
        Panel1.Controls.Add(b)
    Next
    

.

100 .
Panel .
.

, .

.

.
AutoScroll .


:

  • VB.NET
  • autoscroll usercontrol true
  • Dim uc As New UserControl1
    uc.Parent = Me
    Me.Controls.Add(uc)
    uc.Size = New Size(100, 100)
    uc.Location = New Point(0, 0)
    For i As Integer = 1 To 100
        Dim b As New Button()
        b.Text = i.ToString()
        b.Size = New Size(60, 40)
        b.Location = New Point(0, (i * b.Height) - b.Height)
        b.Parent = uc
        uc.Controls.Add(b)
    Next
    

.

( ).
, UserControl, .

+2

- vb.net. .

+1

:

    private void UserControl1_Scroll(object sender, ScrollEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString("hh:mm:ss") + " Scrolling inside" + e.NewValue + " <- " + e.OldValue);
        this.VerticalScroll.Value = e.NewValue;
    }

. .

+1
source

Source: https://habr.com/ru/post/1704229/


All Articles