Hack Forums
[.NET] [Solved]Scrolling a panel without showing scroll bars ? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [Solved]Scrolling a panel without showing scroll bars ? (/showthread.php?tid=5145700)

Pages: Pages 1 2


[Solved]Scrolling a panel without showing scroll bars ? - Dangerous Beef - Jan 24, 2016

I'm working on the Job system which is a Table Layout Panel but I'm working on a panel for testing. I've figured out how to scroll but to hide the scroll bars is a whole other thing.
Since the default scroll bars doesn't match the color theme of my game i can't let them be visible.

Here's the code to scroll within a control:
Quote: Private Sensitivity As Integer = 20
Private Sub panel1_MouseWheel(sender As Object, e As MouseEventArgs) Handles Panel1.MouseWheel
If Panel1.Bounds.Contains(e.Location) Then
Dim vScrollPosition As Integer = Panel1.VerticalScroll.Value
vScrollPosition -= Math.Sign(e.Delta) * Sensitivity
vScrollPosition = Math.Max(0, vScrollPosition)
vScrollPosition = Math.Min(vScrollPosition, Me.VerticalScroll.Maximum)
Panel1.AutoScrollPosition = New Point(Panel1.AutoScrollPosition.X,
vScrollPosition)
Panel1.Invalidate()
End If
End Sub


Been searching around on google and found nothing that worked.

Edit:
Solution(Though not elegant):
Quote: pnl_HideScrollBar.Location = New Point(tlp_Jobs.Location.X + tlp_Jobs.Width - 20, tlp_Jobs.Location.Y)
pnl_HideScrollBar.BackColor = Me.BackColor
tlp_Jobs.MaximumSize = New Point(tlp_Jobs.MaximumSize.Width, Me.Height - tlp_Jobs.Location.Y - 62)
pnl_HideScrollBar.Height = tlp_Jobs.Height




* - 6e756c6c - Jan 24, 2016

Have you tried setting autoscroll on the panel to false?


* - Dangerous Beef - Jan 24, 2016

(Jan 24, 2016 12:39 PM)Aeonhack Wrote:  Have you tried setting autoscroll on the panel to false?

Of course :)
Setting it to false disables my ability to scroll with the mouse wheel.


* - AnonCensored - Jan 24, 2016



If this what you looking for ?

[Image: fbd08bf11f83e9fe839dfd6a75e3b537.gif]

PHP Code

<?php 
For Each ctrl As Control In Panel1.Controls
            Panel1
.AutoScroll = False
        Next 



* - Dangerous Beef - Jan 24, 2016

(Jan 24, 2016 12:46 PM)AnonCensored Wrote:  

If this what you looking for ?

[Image: fbd08bf11f83e9fe839dfd6a75e3b537.gif]

PHP Code

<?php 
For Each ctrl As Control In Panel1.Controls
            Panel1
.AutoScroll = False
        Next 

Like I've said in my previous post disabling AutScroll disables my ability to scroll. Thanks though.


* - 6e756c6c - Jan 24, 2016

You can use the ShowScrollBar function (Windows API, available in Vista and later). Just call it when your form is shown and call it in the MouseWheel event of the Panel. Admittedly though, there is probably a better solution and I haven't done any kind of performance testing. It's something though.

Code
<DllImport("user32.dll", EntryPoint:="ShowScrollBar")> _
    Public Shared Function ShowScrollBar( _
    ByVal handle As IntPtr, _
    ByVal scrollbar As Integer, _
    ByVal visible As Boolean) As Boolean
    End Function

    Private Sub Panel1_MouseWheel(sender As Object, e As MouseEventArgs) Handles Panel1.MouseWheel
        ShowScrollBar(Panel1.Handle, 3, False)
    End Sub

    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        ShowScrollBar(Panel1.Handle, 3, False)
    End Sub



* - AnonCensored - Jan 24, 2016

(Jan 24, 2016 12:51 PM)Dternity Wrote:  Like I've said in my previous post disabling AutScroll disables my ability to scroll. Thanks though.

Oh sorry got confused.. So you want to still be able to scroll but have the visible off right ?

Nvm seems like aerohack has this


* - 6e756c6c - Jan 24, 2016

Actually after testing a little more it appears the solution I provided fails if you activate a control in the panel. Let us know if you get it working though!




Edit 2:
Appears to work, with some flickering, if you also ShowScrollBar in the Panel's child control(s) MouseCaptureChanged events.


* - Dangerous Beef - Jan 24, 2016

(Jan 24, 2016 12:54 PM)Aeonhack Wrote:  Actually after testing a little more it appears the solution I provided fails if you activate a control in the panel. Let us know if you get it working though!




Edit 2:
Appears to work, with some flickering, if you also ShowScrollBar in the Panel's child control(s) MouseCaptureChanged events.

Ehm, where should i put "<DllImport("user32.dll", EntryPoint:="ShowScrollBar")>" ?
[Image: 7AgvBZb.png]


* - AnonCensored - Jan 24, 2016

(Jan 24, 2016 01:01 PM)Dternity Wrote:  Ehm, where should i put "<DllImport("user32.dll", EntryPoint:="ShowScrollBar")>" ?
[Image: 7AgvBZb.png]

Underneath you're form class

[Image: 452c65ff40bec529235816e24d42e29c.gif]


* - Dangerous Beef - Jan 24, 2016

(Jan 24, 2016 01:10 PM)AnonCensored Wrote:  Underneath you're form class

Omg it works, thanks and to you AeonHack.
@AeonHack, Are you sure it won't work for Windows XP users ? Would really like the XP if i could.


* - 6e756c6c - Jan 24, 2016

MSDN for ShowScrollBar says "Minimum supported client: Windows Vista [desktop apps only]". So if you want to support XP (which you honestly shouldn't, it's dead) you'll need to find another method.


* - Dangerous Beef - Jan 24, 2016

(Jan 24, 2016 01:24 PM)Aeonhack Wrote:  MSDN (https://msdn.microsoft.com/en-us/library/windows/desktop/bb787601%28v=vs.85%29.aspx) says "Minimum supported client: Windows Vista [desktop apps only]". So if you want to support XP (which you honestly shouldn't, it's dead) you'll need to find another method.

Haha, the scrolling got all messed up and the scroll bar is flickering on/off the visibility state. I guess I'll just cover the scroll bar up with another panel :/.
https://i.imgur.com/iB7oibz.gifv
Thanks for your help though.


* - Ninja - Jan 24, 2016

(Jan 24, 2016 01:26 PM)Dternity Wrote:  Haha, the scrolling got all messed up and the scroll bar is flickering on/off the visibility state. I guess I'll just cover the scroll bar up with another panel :/.
https://i.imgur.com/iB7oibz.gifv
Thanks for your help though.

You can also capture the scrollevent and programmatically change the child controls in the panel. So when a user scrolls instead of actually scrolling you just make the correct child controls visible and the rest invisible or something.


* - idb. - Jan 24, 2016

Don't have time to look into it for you, and am not sure how the scrollbars work inside of the Panel component exactly, but if they work like most other controls then the scrollbar is actually just another control embedded inside of the Panel itself. Knowing this you can assign the scrollbar to a NativeWindow and subclass the WndProc. Having control over this will allow you to effectively hide the scrollbar without disabling (thus keeping scroll functionality), or you can just override the painting of the scrollbar and choose to not draw anything. Hope this can shed some light.