本文整理汇总了C#中Manina.Windows.Forms.ImageListViewItem.GetCachedImage方法的典型用法代码示例。如果您正苦于以下问题:C# ImageListViewItem.GetCachedImage方法的具体用法?C# ImageListViewItem.GetCachedImage怎么用?C# ImageListViewItem.GetCachedImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Manina.Windows.Forms.ImageListViewItem
的用法示例。
在下文中一共展示了ImageListViewItem.GetCachedImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawItem
/// <summary>
/// Draws the specified item on the given graphics.
/// </summary>
/// <param name="g">The System.Drawing.Graphics to draw on.</param>
/// <param name="item">The ImageListViewItem to draw.</param>
/// <param name="state">The current view state of item.</param>
/// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
{
Clip = (ImageListView.View == Manina.Windows.Forms.View.Details);
if (ImageListView.View != Manina.Windows.Forms.View.Details)
{
Rectangle controlBounds = ClientBounds;
// Zoom on mouse over
if ((state & ItemState.Hovered) != ItemState.None)
{
bounds.Inflate((int)(bounds.Width * mZoomRatio), (int)(bounds.Height * mZoomRatio));
if (bounds.Bottom > controlBounds.Bottom)
bounds.Y = controlBounds.Bottom - bounds.Height;
if (bounds.Top < controlBounds.Top)
bounds.Y = controlBounds.Top;
if (bounds.Right > controlBounds.Right)
bounds.X = controlBounds.Right - bounds.Width;
if (bounds.Left < controlBounds.Left)
bounds.X = controlBounds.Left;
}
// Get item image
Image img = null;
if ((state & ItemState.Hovered) != ItemState.None)
img = GetImageAsync(item, new Size(bounds.Width - 8, bounds.Height - 8));
if (img == null) img = item.GetCachedImage(CachedImageType.Thumbnail);
int imageWidth = 0;
int imageHeight = 0;
if (img != null)
{
// Calculate image bounds
Rectangle pos = Utility.GetSizedImageBounds(img, Rectangle.Inflate(bounds, -4, -4));
imageWidth = pos.Width;
imageHeight = pos.Height;
int imageX = pos.X;
int imageY = pos.Y;
// Allocate space for item text
if ((state & ItemState.Hovered) != ItemState.None &&
(bounds.Height - imageHeight) / 2 < ImageListView.Font.Height + 8)
{
int delta = (ImageListView.Font.Height + 8) - (bounds.Height - imageHeight) / 2;
bounds.Height += 2 * delta;
imageY += delta;
delta = 0;
if (bounds.Bottom > controlBounds.Bottom)
delta = bounds.Y - (controlBounds.Bottom - bounds.Height);
if (bounds.Top < controlBounds.Top)
delta = bounds.Y - controlBounds.Top;
bounds.Y -= delta;
imageY -= delta;
}
// Paint background
if (ImageListView.Enabled)
{
using (Brush bItemBack = new SolidBrush(ImageListView.Colors.BackColor))
{
g.FillRectangle(bItemBack, bounds);
}
}
else
{
using (Brush bItemBack = new SolidBrush(ImageListView.Colors.DisabledBackColor))
{
g.FillRectangle(bItemBack, bounds);
}
}
if ((state & ItemState.Disabled) != ItemState.None)
{
using (Brush bDisabled = new LinearGradientBrush(bounds, ImageListView.Colors.DisabledColor1, ImageListView.Colors.DisabledColor2, LinearGradientMode.Vertical))
{
Utility.FillRoundedRectangle(g, bDisabled, bounds, 5);
}
}
else if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
(!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
{
using (Brush bSelected = new LinearGradientBrush(bounds, ImageListView.Colors.SelectedColor1, ImageListView.Colors.SelectedColor2, LinearGradientMode.Vertical))
{
Utility.FillRoundedRectangle(g, bSelected, bounds, 5);
}
}
else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
{
using (Brush bGray64 = new LinearGradientBrush(bounds, ImageListView.Colors.UnFocusedColor1, ImageListView.Colors.UnFocusedColor2, LinearGradientMode.Vertical))
{
Utility.FillRoundedRectangle(g, bGray64, bounds, 5);
//.........这里部分代码省略.........
示例2: DrawFileIcon
/// <summary>
/// Draws the file icon for the specified item on the given graphics.
/// </summary>
/// <param name="g">The System.Drawing.Graphics to draw on.</param>
/// <param name="item">The ImageListViewItem to draw.</param>
/// <param name="bounds">The bounding rectangle of the file icon in client coordinates.</param>
public override void DrawFileIcon(Graphics g, ImageListViewItem item, Rectangle bounds)
{
Image icon = item.GetCachedImage(CachedImageType.SmallIcon);
if (icon != null && VisualStylesEnabled && rFileIcon != null)
rFileIcon.DrawImage(g, bounds, icon);
else
base.DrawFileIcon(g, item, bounds);
}
示例3: DrawItem
/// <summary>
/// Draws the specified item on the given graphics.
/// </summary>
/// <param name="g">The System.Drawing.Graphics to draw on.</param>
/// <param name="item">The ImageListViewItem to draw.</param>
/// <param name="state">The current view state of item.</param>
/// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.CompositingQuality = CompositingQuality.HighQuality;
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
// Do not draw the background of normal items
if (((state & ItemState.Hovered) != ItemState.None) || ((state & ItemState.Selected) != ItemState.None))
{
// g.FillRectangle(new SolidBrush(Color.Red), bounds);
if (this.ImageListView._palette != null)
{
// (3) Get the renderer associated with this palette
IRenderer renderer = this.ImageListView._palette.GetRenderer();
// (4) Create the rendering context that is passed into all renderer calls
using (RenderContext renderContext = new RenderContext(this.ImageListView, g, bounds, renderer))
{
// (5) Set style required when rendering
this.ImageListView._paletteBack.Style = PaletteBackStyle.ButtonStandalone;
this.ImageListView._paletteBorder.Style = PaletteBorderStyle.ButtonStandalone;
this.ImageListView._paletteContent.Style = PaletteContentStyle.ButtonStandalone;
if (this.ImageListView._paletteBack.GetBackDraw(PaletteState.Normal) == InheritBool.True)
{
using (GraphicsPath path = new GraphicsPath())
{
// (8) Add entire control client area to drawing path
path.AddRectangle(bounds);
// (9) Perform drawing of the background clipped to the path
this.ImageListView._mementoBack1 = renderer.RenderStandardBack.DrawBack(renderContext,
bounds,
path,
this.ImageListView._paletteBack,
VisualOrientation.Top,
GetButtonState(state),
this.ImageListView._mementoBack1);
}
renderer.RenderStandardBorder.DrawBorder(renderContext,bounds, this.ImageListView._paletteBorder, VisualOrientation.Top, PaletteState.Pressed);
}
}
}
}
Size itemPadding = new Size(4,4);
// Draw the image
if (ImageListView.View != View.Details)
{
Image img = item.GetCachedImage(CachedImageType.Thumbnail);
if (img != null)
{
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
// Image background
Rectangle imgback = pos;
imgback.Inflate(3, 3);
g.FillRectangle(SystemBrushes.Window, imgback);
// Image border
if (img.Width > 32 && img.Height > 32)
{
using (Pen pen = new Pen(Color.FromArgb(224, 224, 244)))
{
g.DrawRectangle(pen, imgback.X, imgback.Y, imgback.Width - 1, imgback.Height - 1);
}
}
// Image
g.DrawImage(img, pos);
}
// Draw item text
Size szt = TextRenderer.MeasureText(item.Text, ImageListView.Font);
Rectangle rt = new Rectangle(
bounds.Left + itemPadding.Width, bounds.Top + 2 * itemPadding.Height + ImageListView.ThumbnailSize.Height,
ImageListView.ThumbnailSize.Width, szt.Height);
Color textColor = this.ImageListView._palette.GetContentShortTextColor1(PaletteContentStyle.ButtonListItem, GetButtonState(state));
TextRenderer.DrawText(g, item.Text, ImageListView.Font, rt, textColor,
TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping);
}
else // if (ImageListView.View == View.Details)
{
List<ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();
// Separators
int x = bounds.Left - 2;
foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
{
x += column.Width;
if (!ReferenceEquals(column, uicolumns[uicolumns.Count - 1]))
{
using (Pen pGray32 = new Pen(Color.FromArgb(32, 128, 128, 128)))
{
g.DrawLine(pGray32, x, bounds.Top, x, bounds.Bottom);
//.........这里部分代码省略.........