Author Topic: scrollbar width  (Read 3259 times)

robkwan

  • Newbie
  • *
  • Posts: 44
    • View Profile
scrollbar width
« on: March 02, 2016, 02:06:33 PM »
I need to increase the listview control's vertical scrollbar width to be useable on a touch panel without using a stylus. I am trying to avoid using 2 buttons (up/down) to simulate the scrollbar.

Any suggestion?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5323
    • View Profile
    • AdvancedHMI
Re: scrollbar width
« Reply #1 on: March 02, 2016, 02:26:21 PM »
One method is to add a VScrollBar (from the ToolBox) next to the ListBox, then use this code to have it control the listbox:
Code: [Select]
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
               VScrollBar1.Maximum = ListBox1.Items.Count
    End Sub

    Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles VScrollBar1.Scroll
        ListBox1.TopIndex = VScrollBar1.Value
    End Sub

robkwan

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: scrollbar width
« Reply #2 on: March 02, 2016, 03:00:24 PM »
Archie, nice trick. It is 50% better. The up/dn buttons and the drag bar need to have larger vertical size. Any trick for this?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5323
    • View Profile
    • AdvancedHMI
Re: scrollbar width
« Reply #3 on: March 02, 2016, 04:11:08 PM »
The drag bar can be made larger by increasing the property LargeChange. I don't see anyway to change the arrow button sizes without creating a custom scroll bar.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5323
    • View Profile
    • AdvancedHMI
Re: scrollbar width
« Reply #4 on: March 02, 2016, 06:00:49 PM »
Here is a custom scroll bar that lets you set the ArrowHeight and ThumbHeight. This is basically a framework to start with, it does very little validation so you may want to refine it.

- Download the attached file
- Right click the AdvancedHMI project in Solution Explorer and select Add->Existing Item
- Browse to CustomScrollBar.vb
- Build the project

This is how you would use it:
Code: [Select]
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CustomScrollBar1.Maximum = ListBox1.Items.Count
      End Sub


    Private Sub CustomScrollBar1_ValueChanged(sender As Object, e As EventArgs) Handles CustomScrollBar1.ValueChanged
        ListBox1.TopIndex = CustomScrollBar1.Value
    End Sub
« Last Edit: March 16, 2016, 06:31:03 PM by Archie »

robkwan

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: scrollbar width
« Reply #5 on: March 16, 2016, 06:15:40 PM »
I got the arrows to scroll the listview.
I'm unable to find the correct event for the thumb drag. Need some help to implement the thumb drag scroll.

Edit:
It seems the thumb part has to be done from scratch with the mousedown event as this feature is not in the inherited base object "control"
« Last Edit: March 17, 2016, 09:33:39 AM by robkwan »

Godra

  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: scrollbar width
« Reply #6 on: March 19, 2016, 03:40:48 PM »
You could try the attached control, a combination of Archie's code and code from msdn example:

https://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbarrenderer(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

It is not perfect but should work (especially for touchscreen devices).

Vertical ScrollBar currently has Maximum value at the bottom (not sure how to go about reversing this, might figure it out in the future).

For Windows Forms only, add HVScrollBar.vb file as ExistingItem to PurchasedControls folder.

AHMI version is here: https://www.advancedhmi.com/forum/index.php?topic=1939.0
« Last Edit: February 28, 2019, 08:14:05 PM by Godra »