本文整理汇总了C#中System.Windows.Forms.ListView.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.CreateGraphics方法的具体用法?C# ListView.CreateGraphics怎么用?C# ListView.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListView
的用法示例。
在下文中一共展示了ListView.CreateGraphics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListViewGetHeaderHeight
public override int ListViewGetHeaderHeight (ListView listView, Font font)
{
if (!RenderClientAreas)
return base.ListViewGetHeaderHeight (listView, font);
VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
if (!VisualStyleRenderer.IsElementDefined (element))
return base.ListViewGetHeaderHeight (listView, font);
Control control = null;
Graphics g;
if (listView == null) {
control = new Control ();
g = control.CreateGraphics ();
} else
g = listView.CreateGraphics ();
int result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True).Height;
g.Dispose ();
if (listView == null)
control.Dispose ();
return result;
}
示例2: drawCheckBox
/// <summary>
/// 在ListView的子项里绘制一个checkbox
/// </summary>
/// <param name="listView"></param>
/// <param name="subItem"></param>
/// <param name="isChecked"></param>
private void drawCheckBox(ListView listView, ListViewItem.ListViewSubItem subItem, bool isChecked)
{
Graphics graph = listView.CreateGraphics();
Image icon = getCheckBoxImage(isChecked);
Brush brush = new SolidBrush(subItem.BackColor);
graph.FillRectangle(brush, subItem.Bounds.X + 1, subItem.Bounds.Y + 1, subItem.Bounds.Width - 2, subItem.Bounds.Height - 2);
graph.DrawImage(icon, new Point(subItem.Bounds.X + 5, subItem.Bounds.Y));
graph.Dispose();
}
示例3: GetMaximumColumnWidths
/// <summary>
///
/// </summary>
/// <param name="lv"></param>
/// <returns></returns>
public static Int32[] GetMaximumColumnWidths(ListView lv)
{
Int32 index = 0;
Int32[] widthArray = new Int32[lv.Columns.Count];
foreach (ColumnHeader col in lv.Columns)
{
widthArray[index] = col.Width;
index++;
}
System.Drawing.Graphics g = lv.CreateGraphics();
Int32 offset = Convert.ToInt32(Math.Ceiling(g.MeasureString(" ", lv.Font).Width));
Int32 width = 0;
foreach (ListViewItem item in lv.Items)
{
index = 0;
foreach (ListViewItem.ListViewSubItem subItem in item.SubItems)
{
width = Convert.ToInt32(Math.Ceiling(g.MeasureString(subItem.Text, item.Font).Width)) + offset;
if (width > widthArray[index])
{
widthArray[index] = width;
}
index++;
}
}
g.Dispose();
return widthArray;
}
示例4: AutoResizeColumnWidth
private void AutoResizeColumnWidth(ListView lv)
{
int count = lv.Columns.Count;
int MaxWidth = 0;
Graphics graphics = lv.CreateGraphics();
Font font = lv.Font;
ListView.ListViewItemCollection items = lv.Items;
string str;
int width;
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
for (int i = 0; i < count; i++)
{
str = lv.Columns[i].Text;
MaxWidth = lv.Columns[i].Width;
foreach (ListViewItem item in items)
{
if (item.SubItems.Count > i)
{
str = item.SubItems[i].Text;
width = (int)graphics.MeasureString(str, font).Width;
if (width > MaxWidth)
{
MaxWidth = width;
}
}
}
if (i == 0)
{
lv.Columns[i].Width = lv.SmallImageList.ImageSize.Width + MaxWidth;
}
else if (i == 1)
{
lv.Columns[i].Width = 60;
}
else
{
lv.Columns[i].Width = MaxWidth;
}
}
}