Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have a project with a somewhat custom interface but have yet to find a custom scroll bar control that looks and works well, I have found this code online which does work with and track bar which is good because there are plenty of nice looking customizable track bar controls out there. The problem is the code works in the opposite way so if I scroll up it scrolls down and the maximum is like the minimum. I think this is because the track bar can only be flipped vertical one way with the maximum at the bottom instead of the top. So can the code I have below be modifiyed to work or is there a nice looking custom scroll bar for vb.net?
 
 
    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
        Dim pt As New Point(Me.Panel1.AutoScrollPosition.X, Me.Panel1.AutoScrollPosition.Y)
        Me.CustomScrollBar1.Minimum = 0
        Me.CustomScrollBar1.Maximum = Me.Panel1.DisplayRectangle.Height
        Me.CustomScrollBar1.Value = Math.Abs(Me.Panel1.AutoScrollPosition.Y)
        Me.CustomScrollBar1.Refresh()
        Me.CustomScrollBar1.Update()
    End Sub
 
    Private Sub CustomScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles CustomScrollBar1.Scroll
        Panel1.AutoScrollPosition = New Point(5, CustomScrollBar1.Value)
        CustomScrollBar1.Invalidate()
    End Sub
 
    Private Sub CustomScrollBar1_ValueChanged() Handles CustomScrollBar1.ValueChanged
        Panel1.AutoScrollPosition = New Point(5, CustomScrollBar1.Value)
        CustomScrollBar1.Invalidate()
    End Sub
 
 
Thanks for any help
Posted 31-Jan-13 22:34pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here's what I came up with to get this to do what I wanted... However there are 2 sets of scrollbars... The one for the Panel at 17 pixels and the ones that I designed at 40 pixels.
 
While not perfect, this methodology seems to work!
 
---
 
Public Class Form1
    Inherits System.Windows.Forms.Form
 
#Region " Windows Form Designer generated code "
 
    Public Sub New()
        MyBase.New()
 
        'This call is required by the Windows Form Designer.
        InitializeComponent()
 
        'Add any initialization after the InitializeComponent() call

    End Sub
 
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
   Friend WithEvents Panel1 As System.Windows.Forms.Panel
   Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
   Friend WithEvents Panel2 As System.Windows.Forms.Panel
   Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
   Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
   Friend WithEvents Panel3 As System.Windows.Forms.Panel
   Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar
   Friend WithEvents Splitter2 As System.Windows.Forms.Splitter
   Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Private Sub InitializeComponent()
      Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
      Me.Panel1 = New System.Windows.Forms.Panel
      Me.Panel3 = New System.Windows.Forms.Panel
      Me.VScrollBar1 = New System.Windows.Forms.VScrollBar
      Me.Panel2 = New System.Windows.Forms.Panel
      Me.HScrollBar1 = New System.Windows.Forms.HScrollBar
      Me.PictureBox2 = New System.Windows.Forms.PictureBox
      Me.PictureBox1 = New System.Windows.Forms.PictureBox
      Me.Splitter2 = New System.Windows.Forms.Splitter
      Me.Splitter1 = New System.Windows.Forms.Splitter
      Me.Panel1.SuspendLayout()
      Me.Panel3.SuspendLayout()
      Me.Panel2.SuspendLayout()
      Me.SuspendLayout()
      '
      'Panel1
      '
      Me.Panel1.AutoScroll = True
      Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
      Me.Panel1.Controls.Add(Me.PictureBox1)
      Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
      Me.Panel1.Location = New System.Drawing.Point(0, 0)
      Me.Panel1.Name = "Panel1"
      Me.Panel1.Size = New System.Drawing.Size(494, 408)
      Me.Panel1.TabIndex = 0
      '
      'Panel3
      '
      Me.Panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
      Me.Panel3.Controls.Add(Me.Splitter1)
      Me.Panel3.Controls.Add(Me.VScrollBar1)
      Me.Panel3.Controls.Add(Me.PictureBox2)
      Me.Panel3.Dock = System.Windows.Forms.DockStyle.Right
      Me.Panel3.Location = New System.Drawing.Point(494, 0)
      Me.Panel3.Name = "Panel3"
      Me.Panel3.Size = New System.Drawing.Size(42, 450)
      Me.Panel3.TabIndex = 2
      '
      'VScrollBar1
      '
      Me.VScrollBar1.Dock = System.Windows.Forms.DockStyle.Fill
      Me.VScrollBar1.LargeChange = 50
      Me.VScrollBar1.Location = New System.Drawing.Point(0, 0)
      Me.VScrollBar1.Name = "VScrollBar1"
      Me.VScrollBar1.Size = New System.Drawing.Size(40, 408)
      Me.VScrollBar1.TabIndex = 1
      '
      'Panel2
      '
      Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
      Me.Panel2.Controls.Add(Me.HScrollBar1)
      Me.Panel2.Dock = System.Windows.Forms.DockStyle.Bottom
      Me.Panel2.Location = New System.Drawing.Point(0, 408)
      Me.Panel2.Name = "Panel2"
      Me.Panel2.Size = New System.Drawing.Size(494, 42)
      Me.Panel2.TabIndex = 1
      '
      'HScrollBar1
      '
      Me.HScrollBar1.Dock = System.Windows.Forms.DockStyle.Fill
      Me.HScrollBar1.LargeChange = 50
      Me.HScrollBar1.Location = New System.Drawing.Point(0, 0)
      Me.HScrollBar1.Name = "HScrollBar1"
      Me.HScrollBar1.Size = New System.Drawing.Size(492, 40)
      Me.HScrollBar1.TabIndex = 2
      '
      'PictureBox2
      '
      Me.PictureBox2.Dock = System.Windows.Forms.DockStyle.Bottom
      Me.PictureBox2.Image = CType(resources.GetObject("PictureBox2.Image"), System.Drawing.Image)
      Me.PictureBox2.Location = New System.Drawing.Point(0, 408)
      Me.PictureBox2.Name = "PictureBox2"
      Me.PictureBox2.Size = New System.Drawing.Size(40, 40)
      Me.PictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
      Me.PictureBox2.TabIndex = 0
      Me.PictureBox2.TabStop = False
      '
      'PictureBox1
      '
      Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
      Me.PictureBox1.Location = New System.Drawing.Point(380, 328)
      Me.PictureBox1.Name = "PictureBox1"
      Me.PictureBox1.Size = New System.Drawing.Size(368, 316)
      Me.PictureBox1.TabIndex = 0
      Me.PictureBox1.TabStop = False
      '
      'Splitter2
      '
      Me.Splitter2.Dock = System.Windows.Forms.DockStyle.Bottom
      Me.Splitter2.Enabled = False
      Me.Splitter2.Location = New System.Drawing.Point(0, 407)
      Me.Splitter2.Name = "Splitter2"
      Me.Splitter2.Size = New System.Drawing.Size(494, 1)
      Me.Splitter2.TabIndex = 3
      Me.Splitter2.TabStop = False
      '
      'Splitter1
      '
      Me.Splitter1.BackColor = System.Drawing.Color.Black
      Me.Splitter1.Dock = System.Windows.Forms.DockStyle.Bottom
      Me.Splitter1.Location = New System.Drawing.Point(0, 407)
      Me.Splitter1.Name = "Splitter1"
      Me.Splitter1.Size = New System.Drawing.Size(40, 1)
      Me.Splitter1.TabIndex = 2
      Me.Splitter1.TabStop = False
      Me.Splitter1.Visible = False
      '
      'Form1
      '
      Me.AutoScale = False
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.ClientSize = New System.Drawing.Size(536, 450)
      Me.Controls.Add(Me.Splitter2)
      Me.Controls.Add(Me.Panel1)
      Me.Controls.Add(Me.Panel2)
      Me.Controls.Add(Me.Panel3)
      Me.Name = "Form1"
      Me.Text = "Form1"
      Me.Panel1.ResumeLayout(False)
      Me.Panel3.ResumeLayout(False)
      Me.Panel2.ResumeLayout(False)
      Me.ResumeLayout(False)
 
   End Sub
 
#End Region
 
   Dim PictureRightSize As Integer
   Dim PictureBottomSize As Integer
 
   Dim Panel1Width As Integer
   Dim Panel1Height As Integer
 
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
      'Panel1.AutoScroll = True
      'MsgBox("Sadly the Normal Scrollbar WIDTH and HEIGHT don't seem to be easily resized at this point in time!")

      RecalculateFormScrollBarData()
 
   End Sub
 
   Private Sub RecalculateFormScrollBarData()
 
      ' +17 is for the Panel ScrollBars then Add 10 so that we have a little "wiggle" room!
      Dim ScrollSize As Integer = Panel2.Height + 17 + 10
 
      Panel1Width = Panel1.Width
      Panel1Height = Panel1.Height
 
      PictureRightSize = -Panel1.AutoScrollPosition.X + PictureBox1.Location.X + PictureBox1.Width + ScrollSize - Panel1Width ' + PictureBox1.Width + ScrollSize
      PictureBottomSize = -Panel1.AutoScrollPosition.Y + PictureBox1.Location.Y + PictureBox1.Height + ScrollSize - Panel1Height ' + PictureBox1.Height + ScrollSize

      HScrollBar1.Maximum = PictureRightSize
      VScrollBar1.Maximum = PictureBottomSize
 
      'MsgBox("Panel Bottom Right X, Y Data: " & PictureRightSize & ", " & PictureBottomSize & vbCrLf & vbCrLf & _
      '       "Current Panel X, Y Data: " & Panel1Width & ", " & Panel1Height)

   End Sub
 
   Private Sub Form1_Resize(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Resize
 
      RecalculateFormScrollBarData()
 
   End Sub
 
   Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
 
      'Panel1.AutoScroll = True
      Panel1.AutoScrollPosition = New Point(HScrollBar1.Value, VScrollBar1.Value)
      Panel1.Invalidate()
 
   End Sub
 

   Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
 
      'Panel1.AutoScroll = True
      Panel1.AutoScrollPosition = New Point(HScrollBar1.Value, VScrollBar1.Value)
      Panel1.Invalidate()
 
   End Sub
 
End Class
---
 
In the RecalculateFormScrollBarData routine, the -Panel1.AutoScrollPosition.X and -Panel1.AutoScrollPosition.Y in the calculations allow for the Panel1 Current Location Offset that we are currently viewing is taken into consideration.
 
So this is my best solution at the present time.
 
So this seems to temporarily solve the too small scrollbars for the present time!
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I found a workaround solution for the original question. I too needed a method for extending the size of the ScrollBars.
 
See this thread:
 
http://social.msdn.microsoft.com/Forums/vstudio/en-US/218aaab3-ea2f-43be-bae0-53dc0a912981/visual-basic-2003-how-to-increase-width-and-height-of-a-form-dialogs-scrollbars-for-touch
 

See my post on: Tuesday, July 23, 2013 2:27 AM
 
Hope this helps someone else solve it too!
 
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Maciej Los,
 
The original question shows Visual Basic code. Yet at least 3 of the links you showed use C++ / C# code.
 
I am trying to create my own ScrollBars in Visual Basic because my program will be used in Windows XP, Window 7, and a Windows 8 Tablet PC and 17 pixel wide ScrollBars (Vertical and Horizontal) are just too small to handle with finger gestures on Tablet PCs!
 
Trying to do it in pure code without having to use a Wrapper which then requires extra DLL's, etc to be sent out with my Visual Basic executable.
 
Here's my thread on the MSDN Forums:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/218aaab3-ea2f-43be-bae0-53dc0a912981/visual-basic-2003-how-to-increase-width-and-height-of-a-form-dialogs-scrollbars-for-touch
 
Hope to have the final solution that doesn't require C++ / C# code nor a WRAPPER in my VB.Net 2003 Application.
 
:/
  Permalink  
Comments
Maciej Los at 23-Jul-13 2:42am
   
Dear Destiny,
If you want to post a comment, please, use "Have a question or comment" widget instead posting comment as a solution. Please, delete it to avoid down-voting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 304
2 Richard MacCutchan 225
3 BillWoodruff 169
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 5 Aug 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100