大家好,我创建了一个listbox,有两个问题摆在面前:第一:如何改变ScrollBar的宽度?第二:我另外创建了四个button,“往前翻页”,“往后翻页”,“往下移动光标”,“向上移动”。比如,我的列表里边有20个选项,每页只显示5个,当我按下“往后翻页”按钮后,会显示下5个选项。当我按下“向下移动”按钮后,光标会移动到下一个选项。请问,这些如何实现呢?我在编程方便只能算是个入门级的,希望各问热心人不吝赐教,如何能提供code例示,那就再好不过了!多谢了!!

解决方案 »

  1.   

    http://www.cnblogs.com/peterzb/archive/2009/06/18/1505424.html  看看有没你要的。
      

  2.   

    private void button3_Click(object sender, EventArgs e)
            {
                if (this.listBox1.SelectedIndex + 1 >= this.listBox1.Items.Count)
                {
                    return;
                }
                this.listBox1.SelectedIndex += 1;
            }        private void button4_Click(object sender, EventArgs e)
            {
                if (this.listBox1.SelectedIndex - 1 < 0)
                {
                    return;
                }
                this.listBox1.SelectedIndex -= 1;
            }
      

  3.   

    分页一次查询五条记录填充就行了,或者是一次查询处20条记录利用datatable分页,楼主说的这个ScrollBar不知道是什么?
      

  4.   

    谢了阿,当我运行你的代码的时候,出现了这个错误:error CS0117: 'Menu.Form1' does not contain a definition for 'listBox1_SelectedIndex'。我好久没用C#编程了,不知道为什么会出现这样的问题?
      

  5.   

    scrollbar是listbox自带的,用来翻页或者选择选项的
      

  6.   

    这个我知道,但是它怎么说我没有定义listBox1?error CS0117: 'Menu.Form1' does not contain a definition for 'listBox1'using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    using System.Drawing.Printing;
    using System.Runtime.InteropServices;
    using System.Collections;
    namespace Menu
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.AutoScale = true;
            }        private void label1_Click(object sender, EventArgs e)
            {
               
            }
                    
            private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {        }
           
            private void button2_Click(object sender, EventArgs e)
            {
                if (this.listBox1.SelectedIndex + 1 >= this.listBox1.Items.Count)
                {
                    return;
                }
            }
        }
    }
      

  7.   

    private void button3_Click(object sender, EventArgs e)          {              if (this.listBox1.SelectedIndex + 1 >= this.listBox1.Items.Count)              {                  return;              }              this.listBox1.SelectedIndex += 1;          }            private void button4_Click(object sender, EventArgs e)          {              if (this.listBox1.SelectedIndex - 1  < 0)              {                  return;              }              this.listBox1.SelectedIndex -= 1;          }
      

  8.   

    当我运行程序点击按钮的时候,一个错误信息出现了:“An unhandled exception of type 'System.NullReferenceException' occurred in Menu.exe”. 请问是怎么回事呢?
      

  9.   

    这个问题我解决了,在Form1.Designer.cs里边添加了private System.Windows.Forms.ListBox listBox1后问题就解决了。