当前位置: 首页>>代码示例>>C#>>正文


C# Graphics.DrawIconUnstretched方法代码示例

本文整理汇总了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 );
            }
        }
开发者ID:CecleCW,项目名称:ProductMan,代码行数:55,代码来源:StandardRenderer.cs

示例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;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:DataGridViewImageCell.cs

示例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;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:DataGridViewImageCell.cs

示例4: Draw

	// Draw the cursor.
	public void Draw(Graphics g, Rectangle targetRect)
			{
				if(icon != null)
				{
					g.DrawIconUnstretched(icon, targetRect);
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:Cursor.cs


注:本文中的System.Drawing.Graphics.DrawIconUnstretched方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。