2015-10-13 139 views
1

我在一個需要水平顯示某些項目的項目中工作,這些項​​目就像列表框的項目一樣,所以我將能夠在將項目添加到列表框之前更改項目的文本和屬性。水平列表框可以像這個數字一樣嗎? enter image description here 圖片來源:Horizontal ListView Xamarin.Forms水平列表框

編輯;我與Windows窗體應用程序

+0

要SH哪些物品流?文本?圖片? –

+0

@RezaAghaei它的文本.. –

回答

2

您還可以使用ListView控件:

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); 
} 

結果:

enter image description here

2

工作。雖然我不知道這是否會符合您的要求,但你可以嘗試以下方法:

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. 
+0

設置'lb.Height'稍大一點,以允許滾動條和設置'lb.ColumnWidth'也將有所幫助.. – TaW