Reputation: 65
I'm working in a project which needs to show some items horizontally, the items is like listbox's, so i'll be able to change the texts and attributes of the items before i add those into the listbox.. Is it posible to make horizontal listbox like this figure? image source : Horizontal ListView Xamarin.Forms
EDIT; I'm working with Windows Form Applications
Upvotes: 2
Views: 4624
Reputation: 81610
You can also use a ListView control:
listView1.View = View.Tile;
listView1.Alignment = ListViewAlignment.Left;
listView1.OwnerDraw = true;
listView1.DrawItem += listView1_DrawItem;
listView1.TileSize = new Size(48,
listView1.ClientSize.Height - (SystemInformation.HorizontalScrollBarHeight + 4));
for (int i = 0; i < 25; ++i) {
listView1.Items.Add(new ListViewItem(i.ToString()));
}
void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) {
Color textColor = Color.Black;
if ((e.State & ListViewItemStates.Selected) != 0) {
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
textColor = SystemColors.HighlightText;
} else {
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
}
e.Graphics.DrawRectangle(Pens.DarkGray, e.Bounds);
TextRenderer.DrawText(e.Graphics, e.Item.Text, listView1.Font, e.Bounds,
textColor, Color.Empty,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
}
Result:
Upvotes: 5
Reputation: 3502
Though I am not sure if this will fit your requirement, but you can try following way:
ListBox lb = new ListBox();
lb.MultiColumn = true; //If this is set to false, you see vertical listbox.
lb.Items.AddRange(new object[] { 1, 2, 3, 4, 5, 6, 7, 8 });
lb.Height = 50;
lb.Width = 200;
this.Controls.Add(lb); //I took this dynamic listbox approach just for demo purpose.
Upvotes: 4