I'm creating a winforms app in vb.net and I have a panel with some labels in it. The labels go past the bottom of the panel so the panel shows a vertical scroll bar automatically (which is what I want). However, whenever I scroll the panel down using the mouse wheel, it stops scrolling when one of the labels scrolls up under the mouse. It's like the focus has changed from the panel to the label and the label doesn't need to scroll. I want to just scroll the whole panel using the mouse wheel no matter what comes under the mouse.
相关问题
- 'System.Threading.ThreadAbortException' in
- how to use special characters like '<'
- Use JS/jQuery to scroll a div's content that h
- Jscrollpane - Fires a function when isAtBottom
- C# to VB - How do I convert this anonymous method
相关文章
- vb.net 关于xps文件操作问题
- Checking for DBNull throws a StrongTypingException
- Using the typical get set properties in C#… with p
- SwiftUI automatically scroll to bottom in ScrollVi
- Load a .NET assembly from the application's re
- C# equivalent of VB DLL function declaration (Inte
- What other neat tricks does the SpecialNameAttribu
- Automatically install updates with ClickOnce deplo
A Panel control can't have focus and is not selectable. It's just a container.
You can make a custom control derived from Panel and enable it to receive the focus.
This helps a lot in this situation, because this allows to scroll the custom Panel without any other logic behind.
Even if another control, which usually can get the focus - like a TextBox - gets in the way.
This implementation modifies a Panel control Style (
ControlStyles.Selectable
) to enable it to accept the Focus (theTabStop
property is also set to True).OnMouseDown
is also overidden, so that, if a control inside the Panel steals the Focus, you just need to click on the Panel to move the focus on it and then scroll it.To insert this custom control in a Form, locate it in the ToolBox (at the top of it, look for a control named
PanelWithFocus
) and drop it on the Form.If you want to substitute an existing Panel with this one, open your
Form.Designer
and changeMe.Panel1 = New System.Windows.Forms.Panel()
withMe.Panel1 = New PanelWithFocus()
.The same for
Friend WithEvents Panel1 As Panel
which becomesFriend WithEvents Panel1 As PanelWithFocus
tried this one working fine to me
Create New Panel User Control