本文整理汇总了C#中System.Windows.Forms.ListBox.ScrollAlwaysVisible属性的典型用法代码示例。如果您正苦于以下问题:C# ListBox.ScrollAlwaysVisible属性的具体用法?C# ListBox.ScrollAlwaysVisible怎么用?C# ListBox.ScrollAlwaysVisible使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.ListBox
的用法示例。
在下文中一共展示了ListBox.ScrollAlwaysVisible属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeOwnerDrawnListBox
internal System.Windows.Forms.ListBox ListBox1;
private void InitializeOwnerDrawnListBox()
{
this.ListBox1 = new System.Windows.Forms.ListBox();
// Set the location and size.
ListBox1.Location = new Point(20, 20);
ListBox1.Size = new Size(240, 240);
// Populate the ListBox.ObjectCollection property
// with several strings, using the AddRange method.
this.ListBox1.Items.AddRange(new object[]{"System.Windows.Forms",
"System.Drawing", "System.Xml", "System.Net", "System.Runtime.Remoting",
"System.Web"});
// Turn off the scrollbar.
ListBox1.ScrollAlwaysVisible = false;
// Set the border style to a single, flat border.
ListBox1.BorderStyle = BorderStyle.FixedSingle;
// Set the DrawMode property to the OwnerDrawVariable value.
// This means the MeasureItem and DrawItem events must be
// handled.
ListBox1.DrawMode = DrawMode.OwnerDrawVariable;
ListBox1.MeasureItem +=
new MeasureItemEventHandler(ListBox1_MeasureItem);
ListBox1.DrawItem += new DrawItemEventHandler(ListBox1_DrawItem);
this.Controls.Add(this.ListBox1);
}
// Handle the DrawItem event for an owner-drawn ListBox.
private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
{
// If the item is the selected item, then draw the rectangle
// filled in blue. The item is selected when a bitwise And
// of the State property and the DrawItemState.Selected
// property is true.
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.Graphics.FillRectangle(Brushes.CornflowerBlue, e.Bounds);
}
else
{
// Otherwise, draw the rectangle filled in beige.
e.Graphics.FillRectangle(Brushes.Beige, e.Bounds);
}
// Draw a rectangle in blue around each item.
e.Graphics.DrawRectangle(Pens.Blue, e.Bounds);
// Draw the text in the item.
e.Graphics.DrawString(ListBox1.Items[e.Index].ToString(),
this.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
// Draw the focus rectangle around the selected item.
e.DrawFocusRectangle();
}
// Handle the MeasureItem event for an owner-drawn ListBox.
private void ListBox1_MeasureItem(object sender,
MeasureItemEventArgs e)
{
// Cast the sender object back to ListBox type.
ListBox theListBox = (ListBox) sender;
// Get the string contained in each item.
string itemString = (string) theListBox.Items[e.Index];
// Split the string at the " . " character.
string[] resultStrings = itemString.Split('.');
// If the string contains more than one period, increase the
// height by ten pixels; otherwise, increase the height by
// five pixels.
if (resultStrings.Length>2)
{
e.ItemHeight += 10;
}
else
{
e.ItemHeight += 5;
}
}
示例2: ListBoxSelectionMode
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class ListBoxSelectionMode : Form
{
ListBox lb;
RadioButton rdoMultiExtended;
RadioButton rdoMultiSimple;
RadioButton rdoMultiOne;
TextBox txtTop;
Button btnTop;
public ListBoxSelectionMode()
{
int xSize, ySize;
Size = new Size(300,400);
lb = new ListBox();
lb.Parent = this;
lb.Location = new Point(10,10);
lb.Size = new Size(ClientSize.Width - 20, Height - 200);
lb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
lb.BorderStyle = BorderStyle.Fixed3D;
lb.MultiColumn = true;
lb.ScrollAlwaysVisible = true;
GroupBox grpMulti = new GroupBox();
grpMulti.Parent = this;
grpMulti.Text = "MultiSelect";
grpMulti.Location = new Point(lb.Left, lb.Bottom + 25);
grpMulti.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
rdoMultiOne = new RadioButton();
rdoMultiOne.Parent = grpMulti;
rdoMultiOne.Text = "One";
rdoMultiOne.Tag = SelectionMode.One;
rdoMultiOne.Checked = true;
rdoMultiOne.Location = new Point(10,15);
rdoMultiOne.CheckedChanged += new System.EventHandler(rdoMulti_CheckedChanged);
rdoMultiSimple = new RadioButton();
rdoMultiSimple.Parent = grpMulti;
rdoMultiSimple.Text = "Multi-Simple";
rdoMultiSimple.Tag = SelectionMode.MultiSimple;
rdoMultiSimple.Location = new Point(10, rdoMultiOne.Bottom);
rdoMultiSimple.CheckedChanged += new System.EventHandler(rdoMulti_CheckedChanged);
rdoMultiExtended = new RadioButton();
rdoMultiExtended.Parent = grpMulti;
rdoMultiExtended.Text = "Multi-Extended";
rdoMultiExtended.Tag = SelectionMode.MultiExtended;
rdoMultiExtended.Location = new Point(10, rdoMultiSimple.Bottom);
rdoMultiExtended.CheckedChanged += new System.EventHandler(rdoMulti_CheckedChanged);
xSize = (int)(Font.Height * .75) * rdoMultiExtended.Text.Length;
ySize = ((int)rdoMultiOne.Height * 3) + 20;
grpMulti.Size = new Size(xSize, ySize);
Panel pnlTop = new Panel();
pnlTop.Parent = this;
pnlTop.Location = new Point(lb.Left, grpMulti.Bottom + 10);
pnlTop.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
Label lblTop = new Label();
lblTop.Parent = pnlTop;
lblTop.Text = "TopIndex: ";
xSize = ((int)(Font.Height * .5) * lblTop.Text.Length);
lblTop.Size = new Size(xSize, Font.Height + 10);
txtTop = new TextBox();
txtTop.Parent = pnlTop;
txtTop.Location = new Point(lblTop.Right, lblTop.Top);
txtTop.Text = lb.TopIndex.ToString();
txtTop.Size = new Size((int)(Font.Height * .75) * 3,
Font.Height + 10);
btnTop = new Button();
btnTop.Parent = pnlTop;
btnTop.Text = "Update";
btnTop.Location = new Point(txtTop.Right + 10, txtTop.Top);
btnTop.Click += new System.EventHandler(btnTop_Click);
lb.Items.Add("12345");
lb.Items.Add("67890");
lb.Items.Add("7890");
lb.Items.Add("890");
}
static void Main()
{
Application.Run(new ListBoxSelectionMode());
}
private void rdoMulti_CheckedChanged(object sender, EventArgs e)
{
RadioButton rdo = (RadioButton)sender;
lb.SelectionMode = (SelectionMode)rdo.Tag;
}
private void btnTop_Click(object sender, EventArgs e)
{
txtTop.Text = lb.TopIndex.ToString();
}
}