绘制listview列并分别对齐列

时间:2013-04-02 07:19:04

标签: c# listview alignment drawstring string-formatting

我在打印之前绘制了listview,我可以使用StringAlignment.Far将列对齐,但是它会向右绘制所有列,我可以将我的第一个描述列绘制到左边,将price列绘制到右边吗?

           if (Controls[i].GetType() == this.listView1.GetType())
            {
                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment = StringAlignment.Far;
                stringFormat.LineAlignment = StringAlignment.Far;
                for (int row = 0; row < listView1.Items.Count; row++)
                {
                    int nextColumnPosition = listView1.Bounds.X;
                    for (int col = 0; col < listView1.Items[row].SubItems.Count; col++)
                    {
                        g.DrawString(listView1.Items[row].SubItems[col].Text, listView1.Items[row].Font, Brushes.Black, (nextColumnPosition + 3) * scalex, (listView1.Items[row].Bounds.Y + listView1.Bounds.Y) * scaley, stringFormat);
                        nextColumnPosition += listView1.Columns[col].Width;

                    }
                }
            }  

0 个答案:

没有答案