C# 学习笔记--控件

1. ListBox

属性列表:

    SelectionMode    组件中条目的选择类型,即多选(Multiple)、单选(Single)
    Rows                  列表框中显示总共多少行
    Selected             检测条目是否被选中
    SelectedItem      返回的类型是ListItem,获得列表框中被选择的条目
    Count                  列表框中条目的总数
    SelectedIndex    列表框中被选择项的索引值
    Items                  泛指列表框中的所有项,每一项的类型都是ListItem

ListBox.Items.Remove(  ListBox.SelectedItem  );                  //移除选中项

ListBox.SelectedValue                                                           //被选中的值

ListBox.Items.Add( "A1 :" +  HDid.ToString() );                      //动态添加项  String HDid;  

switch(  ListBox1.SelectValue  )                                             // 分别响应listbox中的选项  

ListBox1.Items.Insert( 0 , new   ListItem("text","value"));       //插入

      index = -1;
      //将当前条目的文本以及值都保存到一个临时变量里面
      ListItem lt=new ListItem (ListBox.SelectedItem.Text,ListBox.SelectedValue);
      //被选中的项的值等于上一条或下一条的值
      ListBox.Items[ListBox.SelectedIndex].Text=ListBox.Items[ListBox.SelectedIndex + index].Text;
      //被选中的项的值等于上一条或下一条的值
      ListBox.Items[ListBox.SelectedIndex].Value=ListBox.Items[ListBox.SelectedIndex + index].Value;
      //把被选中项的前一条或下一条的值用临时变量中的取代
      ListBox.Items[ListBox.SelectedIndex].Test=lt.Test;
      //把被选中项的前一条或下一条的值用临时变量中的取代
      ListBox.Items[ListBox.SelectedIndex].Value=lt.Value;
      //把鼠标指针放到移动后的那项上
      ListBox.Items[ListBox.SelectedIndex].Value=lt.Value;   

2  picturebox

 1)静态加载图片:image属性

 2)动态加载图片:

 3)适应图片大小:sizemode=stretchimage

三 获取屏幕大小

            Rectangle rect = new Rectangle();
            rect = Screen.GetWorkingArea(this);
            this.Width = rect.Width;     //屏幕宽
            this.Height = rect.Height;   //屏幕高


四  随机数

 Random rd = new Random();
 int picture_left1 = rd.Next(5,20);


 

 

 

 

 

 

 

 

 

 

 

              

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值