Winform控件开发(9)

您所在的位置:网站首页 winform窗口跳转 Winform控件开发(9)

Winform控件开发(9)

2023-03-27 04:17| 来源: 网络整理| 查看: 265

一、属性

// Create an instance of the ListBox.ListBox listBox1 = new ListBox();// Set the size and location of the ListBox.listBox1.Size = new System.Drawing.Size(200, 100);listBox1.Location = new System.Drawing.Point(10, 10);// Add the ListBox to the form.this.Controls.Add(listBox1);// Set the ListBox to display items in multiple columns.listBox1.MultiColumn = true ;// Set the selection mode to multiple and extended.listBox1.SelectionMode = SelectionMode.MultiExtended ;// Shutdown the painting of the ListBox as items are added.listBox1.BeginUpdate();//如果不指定的话,每次添加一个项都要绘制一次,降低了性能// Loop through and add 50 items to the ListBox.for (int x = 1; x 50; x++){listBox1.Items.Add("Item " + x.ToString());}// Allow the ListBox to repaint and display the new items.listBox1.EndUpdate();// Select three items from the ListBox.listBox1.SetSelected(1, true);listBox1.SetSelected(3, true);listBox1.SetSelected(5, true);

1、MultiColumn false) 没有多列,不管添加多少项,都是增加了行数,如果不够显示则使用垂直滚动条 在这里插入图片描述 true) 超出控件高度时则显示在第二列,此时列宽为0,也可以指定列宽 在这里插入图片描述 2、ColumnWidth 下图是列宽为50时的结果。 在这里插入图片描述 3、HorizontalExtent(当MultiColumn为true时无效) 水平滚动条可滚动的宽度,也就是通过滚动条,可以将控件显示的宽度扩大到多少像素,并且该属性只有在HorizontalScrollbar = true时才生效 比如下图没有水平滚动条 在这里插入图片描述 当将HorizontalExtent扩大为500,HorizontalScrollbar = true时,如下: 在这里插入图片描述 在这里插入图片描述 4、HorizontalScrollbar 指示是否在控件中显示水平滚动条,当内容超出显示宽度时显示水平滚动条。 5、IntegralHeight 不知道有什么作用,如果有知道的评论区分享一下哦。 6、ItemHeight 每一项的高度,也就是每一行的高度,由字体大小决定,当drawmode为Normal时 7、ScrollAlwaysVisible 指示控件是否始终显示垂直滚动条,而不是只有内容超出控件范围才显示滚动条 8、SelectionMode 1) SelectionMode.One 一次只能选择一个 2) SelectionMode.None 无法选择 3)SelectionMode.MultiSimple 可以选择多项,鼠标点击一项就选中,再次点击就取消选中 3)SelectionMode.MultiExtended 可以选择多项,然后支持crtl,shift,以及鼠标拖动选中。 9、Sorted 指示列表中的项是否按照字母排序,比如从a到z,比如从1到9,如果想要更加详细的排序,可以自己先将项排好,然后再显示; 10、UseTabStops 指示 ListBox 在绘制其字符串时是否可识别和展开制表符,代码如下: 该属性为true时)

for (int x = 1; x 20; x++){listBox1.Items.Add("Item\t" + x.ToString());}

在这里插入图片描述 该属性为false时) 在这里插入图片描述 二、事件 1、SelectedIndex 选择的项发生了变化 2、SelectedValue 选择的项的值发生了变化



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3