Results 1 to 4 of 4

Thread: How to disable scrolling in a panel.

  1. #1
    elie is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Dec 2011
    Posts
    4
    Reputation
    0

    How to disable scrolling in a panel.

    A panel with enabled scrollbars has many buttons. If I push the tabulation key, focus navigates between buttons.
    When a partially visible button has focus, the panel scrolls itself in order to completely show the button.
    Is there a way to prevent that scrolling?

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    I haven't look very deep into this, but a simple way to achieve that is to write a class that inherits Panel and override ScrollToControl method, where you return AutoScrollPosition. That would make ScrollControlIntoView method useless for that Panel as well.

  3. #3
    elie is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Dec 2011
    Posts
    4
    Reputation
    0
    Quote Originally Posted by JohnH View Post
    I haven't look very deep into this, but a simple way to achieve that is to write a class that inherits Panel and override ScrollToControl method, where you return AutoScrollPosition. That would make ScrollControlIntoView method useless for that Panel as well.
    When I try to override the ScrollToControl Method, I get the following message:

    "function ScrollToControl cannot be declared 'Overrides' because it does not override a function in a base class"

    My code is the following:

    Public Class MyPanel
    Inherits Panel

    Protected overrides function ScrollToControl (Byval activeControl as Control) As Point
    return me.autoscrollPosition
    End Function

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    In a Windows Forms application intellisense generates this code:
            Protected Overrides Function ScrollToControl(activeControl As System.Windows.Forms.Control) As System.Drawing.Point
    Return MyBase.ScrollToControl(activeControl)
    End Function

    Where only the return value need to be changed, as I explained. The code is very similar to what you posted, still it indicates you have written that code manually, but in the forms app it is valid.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking