zoukankan      html  css  js  c++  java
  • listbox的索引问题

    1、UI

    2、代码

    [csharp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.ComponentModel;  
    4. using System.Data;  
    5. using System.Drawing;  
    6. using System.Linq;  
    7. using System.Text;  
    8. using System.Threading.Tasks;  
    9. using System.Windows.Forms;  
    10.   
    11. namespace WindowsFormsApplication8  
    12. {  
    13.     public partial class Form1 : Form  
    14.     {  
    15.         public Form1()  
    16.         {  
    17.             InitializeComponent();  
    18.         }  
    19.   
    20.          
    21.         /// <summary>  
    22.         /// 显示当前的listbox的索引值  
    23.         /// </summary>  
    24.         /// <param name="sender"></param>  
    25.         /// <param name="e"></param>  
    26.         private void button3_Click(object sender, EventArgs e)  
    27.         {  
    28.             MessageBox.Show(listBox1.SelectedIndex.ToString());  
    29.         }  
    30.   
    31.         /// <summary>  
    32.         /// 让蓝条向上,循环移动  
    33.         /// </summary>  
    34.         /// <param name="sender"></param>  
    35.         /// <param name="e"></param>  
    36.         private void buttonShang_Click(object sender, EventArgs e)  
    37.         {  
    38.             if(listBox1.SelectedIndex==0)  
    39.             {  
    40.                 listBox1.SelectedIndex = listBox1.Items.Count-1;  
    41.             }  
    42.             else  
    43.             {  
    44.                 listBox1.SelectedIndex--;  
    45.             }  
    46.         }  
    47.   
    48.         /// <summary>  
    49.         /// 有了这个默认值,就好像有了参考系一样。简化了很多代码  
    50.         /// </summary>  
    51.         /// <param name="sender"></param>  
    52.         /// <param name="e"></param>  
    53.         private void Form1_Load(object sender, EventArgs e)  
    54.         {  
    55.             //在窗体加载的时候就给Listbox一个默认值吧,这样可以简化代码  
    56.             listBox1.SelectedIndex = 0;  
    57.         }  
    58.   
    59.         /// <summary>  
    60.         /// 让蓝条向下循环移动  
    61.         /// </summary>  
    62.         /// <param name="sender"></param>  
    63.         /// <param name="e"></param>  
    64.         private void buttonXia_Click(object sender, EventArgs e)  
    65.         {  
    66.             if (listBox1.SelectedIndex == listBox1.Items.Count - 1)  
    67.             {  
    68.                 listBox1.SelectedIndex = 0;  
    69.             }  
    70.             else  
    71.             {  
    72.                 listBox1.SelectedIndex++;  
    73.             }  
    74.         }  
    75.     }  
    76. }  



    3、效果图





  • 相关阅读:
    php的运行模式
    PostgreSQL指定用户可访问的数据库pg_hba.conf
    PostgreSQL创建只读用户
    Python操作PostGreSQL数据库
    Python爬虫基础示例
    Linux下设置tomcat开机自启
    Windows下配置jar环境
    警告1909。无法创建快捷方式VMware Workstation Pro.Ink。解决方法(附 VMware_workstation 12的安装方法)
    删数问题
    An Easy Problem
  • 原文地址:https://www.cnblogs.com/wanzhongjun/p/6273486.html
Copyright © 2011-2022 走看看