本文整理汇总了C#中System.Drawing.Graphics.DrawIconUnstretched方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.DrawIconUnstretched方法的具体用法?C# Graphics.DrawIconUnstretched怎么用?C# Graphics.DrawIconUnstretched使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.DrawIconUnstretched方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderTreeNode
public void RenderTreeNode( Graphics g, ITreeInfo treeInfo, TreeNode treeNode, Rectangle nodeRectangle, Rectangle clip )
{
bool isLast = (treeNode.Index == treeNode.ParentCollection.Count - 1);
Size ecSize = GetGlyphSize( g, treeNode.IsExpanded );
Point ecCenter = new Point( nodeRectangle.X + _leftSep + ecSize.Width / 2, nodeRectangle.Y + (nodeRectangle.Height - ecSize.Height) / 2 + ecSize.Height / 2 );
using( Brush brush = new HatchBrush( HatchStyle.Percent50, SystemColors.Window, SystemColors.GrayText ) )
using( Pen pen = new Pen( brush ) )
{
g.DrawLine( pen, ecCenter, new Point( ecCenter.X + 12, ecCenter.Y ) );
g.DrawLine( pen, ecCenter, new Point( ecCenter.X, nodeRectangle.Y ) );
if( !isLast )
{
g.DrawLine( pen, ecCenter, new Point( ecCenter.X, nodeRectangle.Bottom ) );
}
}
int textX = nodeRectangle.X + ecSize.Width + _leftSep + _ecSep;
if( treeNode.Icon != null )
{
Icon image = treeNode.Icon;
g.DrawIconUnstretched( image, new Rectangle( textX, nodeRectangle.Y + (nodeRectangle.Height - image.Height) / 2, image.Width, image.Height ) );
textX += image.Width + _imageSep;
}
if( treeInfo.IsSelected( treeNode ) )
{
Brush brush = treeInfo.IsTreeFocused() ? SystemBrushes.Highlight : SystemBrushes.Control;
g.FillRectangle( brush, textX, nodeRectangle.Y, nodeRectangle.Right - textX + 2, nodeRectangle.Height - 1 );
if( treeInfo.IsTreeFocused() )
{
using( Brush hatchBrush = new HatchBrush( HatchStyle.Percent50, SystemColors.Highlight ) )
using( Pen pen = new Pen( hatchBrush ) )
{
g.DrawRectangle( pen, textX, nodeRectangle.Y, nodeRectangle.Right - textX + 2, nodeRectangle.Height - 1 );
}
}
}
WinFormsUtility.Drawing.GdiPlusEx.DrawString
( g, treeNode.Text, treeNode.Font, SystemColors.ControlText
, new Rectangle( textX + 2, nodeRectangle.Y + _verticalSep, int.MaxValue, int.MaxValue )
, WinFormsUtility.Drawing.GdiPlusEx.TextSplitting.SingleLineEllipsis, WinFormsUtility.Drawing.GdiPlusEx.Ampersands.Display );
if( treeNode.ChildNodes.Count > 0 )
{
DrawGlyph( g, new Point( nodeRectangle.X + _leftSep, nodeRectangle.Y + (nodeRectangle.Height - ecSize.Height) / 2 ), treeNode.IsExpanded );
}
}
示例2: PaintPrivate
//.........这里部分代码省略.........
Image image = formattedValue as Image;
Icon icon = null;
if (image == null)
{
icon = formattedValue as Icon;
}
if ((icon != null) || (image != null))
{
DataGridViewImageCellLayout imageLayout = this.ImageLayout;
switch (imageLayout)
{
case DataGridViewImageCellLayout.NotSet:
if (base.OwningColumn is DataGridViewImageColumn)
{
imageLayout = ((DataGridViewImageColumn) base.OwningColumn).ImageLayout;
}
else
{
imageLayout = DataGridViewImageCellLayout.Normal;
}
break;
case DataGridViewImageCellLayout.Stretch:
if (paint)
{
if (DataGridViewCell.PaintBackground(paintParts))
{
DataGridViewCell.PaintPadding(g, cellValueBounds, cellStyle, cachedBrush, base.DataGridView.RightToLeftInternal);
}
if (DataGridViewCell.PaintContentForeground(paintParts))
{
if (image != null)
{
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetWrapMode(WrapMode.TileFlipXY);
g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
imageAttr.Dispose();
}
else
{
g.DrawIcon(icon, destRect);
}
}
}
empty = destRect;
goto Label_037E;
}
Rectangle a = this.ImgBounds(destRect, (image == null) ? icon.Width : image.Width, (image == null) ? icon.Height : image.Height, imageLayout, cellStyle);
empty = a;
if (paint)
{
if (DataGridViewCell.PaintBackground(paintParts) && (cachedBrush.Color.A == 0xff))
{
g.FillRectangle(cachedBrush, cellValueBounds);
}
if (DataGridViewCell.PaintContentForeground(paintParts))
{
Region clip = g.Clip;
g.SetClip(Rectangle.Intersect(Rectangle.Intersect(a, destRect), Rectangle.Truncate(g.VisibleClipBounds)));
if (image != null)
{
g.DrawImage(image, a);
}
else
{
g.DrawIconUnstretched(icon, a);
}
g.Clip = clip;
}
}
}
else
{
if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff))
{
g.FillRectangle(cachedBrush, cellValueBounds);
}
empty = Rectangle.Empty;
}
}
else
{
if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff))
{
g.FillRectangle(cachedBrush, cellValueBounds);
}
empty = Rectangle.Empty;
}
Label_037E:
point = base.DataGridView.CurrentCellAddress;
if (((paint && DataGridViewCell.PaintFocus(paintParts)) && ((point.X == base.ColumnIndex) && (point.Y == rowIndex))) && (base.DataGridView.ShowFocusCues && base.DataGridView.Focused))
{
ControlPaint.DrawFocusRectangle(g, cellValueBounds, Color.Empty, cachedBrush.Color);
}
if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts))
{
base.PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText);
}
return empty;
}
示例3: PaintPrivate
//.........这里部分代码省略.........
// bug 21949: Graphics.DrawImage does not treat well scaled images
// we have to pass an ImageAttribute
ImageAttributes attr = new ImageAttributes();
attr.SetWrapMode(WrapMode.TileFlipXY);
g.DrawImage(img, imgBounds, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attr);
attr.Dispose();
}
else
{
g.DrawIcon(ico, imgBounds);
}
}
}
resultBounds = imgBounds;
}
else
{
Rectangle imgBounds2 = ImgBounds(imgBounds, (img == null) ? ico.Width : img.Width, (img == null) ? ico.Height : img.Height, imageLayout, cellStyle);
resultBounds = imgBounds2;
if (paint)
{
if (DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255)
{
g.FillRectangle(br, valBounds);
}
if (DataGridViewCell.PaintContentForeground(paintParts))
{
//paint the image
Region reg = g.Clip;
g.SetClip(Rectangle.Intersect(Rectangle.Intersect(imgBounds2, imgBounds), Rectangle.Truncate(g.VisibleClipBounds)));
if (img != null)
{
g.DrawImage(img, imgBounds2);
}
else
{
g.DrawIconUnstretched(ico, imgBounds2);
}
g.Clip = reg;
}
}
}
}
else
{
if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255)
{
g.FillRectangle(br, valBounds);
}
resultBounds = Rectangle.Empty;
}
}
else
{
if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255)
{
g.FillRectangle(br, valBounds);
}
resultBounds = Rectangle.Empty;
}
Point ptCurrentCell = this.DataGridView.CurrentCellAddress;
if (paint &&
DataGridViewCell.PaintFocus(paintParts) &&
ptCurrentCell.X == this.ColumnIndex &&
ptCurrentCell.Y == rowIndex &&
this.DataGridView.ShowFocusCues &&
this.DataGridView.Focused)
{
// Draw focus rectangle
ControlPaint.DrawFocusRectangle(g, valBounds, Color.Empty, br.Color);
}
if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts))
{
PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, valBounds, errorText);
}
}
else if (computeErrorIconBounds)
{
if (!String.IsNullOrEmpty(errorText))
{
resultBounds = ComputeErrorIconBounds(valBounds);
}
else
{
resultBounds = Rectangle.Empty;
}
}
else
{
Debug.Assert(valBounds.Height <= 0 || valBounds.Width <= 0);
resultBounds = Rectangle.Empty;
}
return resultBounds;
}
示例4: Draw
// Draw the cursor.
public void Draw(Graphics g, Rectangle targetRect)
{
if(icon != null)
{
g.DrawIconUnstretched(icon, targetRect);
}
}