C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,188 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All,
I test if Vertical Scrollbar can work with listBox.
below th code.It look like cannot go to the bottom Item.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Learning_10
{
public partial class Form1 : Form
{
// VScrollBar vScroller = new VScrollBar();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
vScrollBar1.Height = listBox1.Height;
vScrollBar1.Left = listBox1.Left + listBox1.Width;
vScrollBar1.Top = listBox1.Top;
vScrollBar1.Maximum = listBox1.Height;
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 500; i++)
{
listBox1.Items.Add(i);
}
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
listBox1.SelectedIndex = e.NewValue;
}
}
}
vScrollBar1.Maximum is wrong, it should be = listBox1.Items.Count; (after the ListBox has been filled)
and in vScrollBar1_Scroll, it should be :
listBox1.TopIndex = e.NewValue;