System.Drawing.Graphics.DrawIcon C# (CSharp) Method

DrawIcon() public method

public DrawIcon ( Icon icon, Rectangle targetRect ) : void
icon Icon
targetRect Rectangle
return void
        public void DrawIcon(Icon icon, Rectangle targetRect)
        {
            if (icon == null)
                throw new ArgumentNullException ("icon");

            //DrawImage (icon.GetInternalBitmap (), targetRect);
            throw new NotImplementedException ();
        }

Same methods

Graphics::DrawIcon ( Icon icon, int x, int y ) : void

Usage Example

Example #1
4
        /// <summary>Internal method for rendering an individual <paramref name="tab" /> to the screen.</summary>
        /// <param name="graphicsContext">Graphics context to use when rendering the tab.</param>
        /// <param name="tab">Individual tab that we are to render.</param>
        /// <param name="area">Area of the screen that the tab should be rendered to.</param>
        /// <param name="cursor">Current position of the cursor.</param>
        protected virtual void Render(Graphics graphicsContext, TitleBarTab tab, Rectangle area, Point cursor)
        {
            if (_suspendRendering)
            {
                return;
            }

            // If we need to redraw the tab image
            if (tab.TabImage == null)
            {
                // We render the tab to an internal property so that we don't necessarily have to redraw it in every rendering pass, only if its width or
                // status have changed
                tab.TabImage = new Bitmap(
                    area.Width, tab.Active
                        ? _activeCenterImage.Height
                        : _inactiveCenterImage.Height);

                using (Graphics tabGraphicsContext = Graphics.FromImage(tab.TabImage))
                {
                    // Draw the left, center, and right portions of the tab
                    tabGraphicsContext.DrawImage(
                        tab.Active
                            ? _activeLeftSideImage
                            : _inactiveLeftSideImage, new Rectangle(
                                0, 0, tab.Active
                                    ? _activeLeftSideImage
                                        .Width
                                    : _inactiveLeftSideImage
                                        .Width,
                                tab.Active
                                    ? _activeLeftSideImage.
                                        Height
                                    : _inactiveLeftSideImage
                                        .Height), 0, 0,
                        tab.Active
                            ? _activeLeftSideImage.Width
                            : _inactiveLeftSideImage.Width, tab.Active
                                ? _activeLeftSideImage.Height
                                : _inactiveLeftSideImage.Height,
                        GraphicsUnit.Pixel);

                    tabGraphicsContext.DrawImage(
                        tab.Active
                            ? _activeCenterImage
                            : _inactiveCenterImage, new Rectangle(
                                (tab.Active
                                    ? _activeLeftSideImage.
                                        Width
                                    : _inactiveLeftSideImage
                                        .Width), 0,
                                _tabContentWidth, tab.Active
                                    ? _activeCenterImage
                                        .
                                        Height
                                    : _inactiveCenterImage
                                        .
                                        Height),
                        0, 0, _tabContentWidth, tab.Active
                            ? _activeCenterImage.Height
                            : _inactiveCenterImage.Height,
                        GraphicsUnit.Pixel);

                    tabGraphicsContext.DrawImage(
                        tab.Active
                            ? _activeRightSideImage
                            : _inactiveRightSideImage, new Rectangle(
                                (tab.Active
                                    ? _activeLeftSideImage
                                        .Width
                                    : _inactiveLeftSideImage
                                        .Width) +
                                _tabContentWidth, 0,
                                tab.Active
                                    ? _activeRightSideImage
                                        .Width
                                    : _inactiveRightSideImage
                                        .Width,
                                tab.Active
                                    ? _activeRightSideImage
                                        .Height
                                    : _inactiveRightSideImage
                                        .Height), 0, 0,
                        tab.Active
                            ? _activeRightSideImage.Width
                            : _inactiveRightSideImage.Width, tab.Active
                                ? _activeRightSideImage.Height
                                : _inactiveRightSideImage.
                                    Height,
                        GraphicsUnit.Pixel);

                    // Draw the close button
                    if (tab.ShowCloseButton)
                    {
                        Image closeButtonImage = IsOverCloseButton(tab, cursor)
                            ? _closeButtonHoverImage
                            : _closeButtonImage;

                        tab.CloseButtonArea = new Rectangle(
                            area.Width - (tab.Active
                                ? _activeRightSideImage.Width
                                : _inactiveRightSideImage.Width) -
                            CloseButtonMarginRight - closeButtonImage.Width,
                            CloseButtonMarginTop, closeButtonImage.Width,
                            closeButtonImage.Height);

                        tabGraphicsContext.DrawImage(
                            closeButtonImage, tab.CloseButtonArea, 0, 0,
                            closeButtonImage.Width, closeButtonImage.Height,
                            GraphicsUnit.Pixel);
                    }
                }

                tab.Area = area;
            }

            // Render the tab's saved image to the screen
            graphicsContext.DrawImage(
                tab.TabImage, area, 0, 0, tab.TabImage.Width, tab.TabImage.Height,
                GraphicsUnit.Pixel);

            // Render the icon for the tab's content, if it exists and there's room for it in the tab's content area
            if (tab.Content.ShowIcon && _tabContentWidth > 16 + IconMarginLeft + (tab.ShowCloseButton
                ? CloseButtonMarginLeft +
                  tab.CloseButtonArea.Width +
                  CloseButtonMarginRight
                : 0))
            {
                graphicsContext.DrawIcon(
                    new Icon(tab.Content.Icon, 16, 16),
                    new Rectangle(area.X + OverlapWidth + IconMarginLeft, IconMarginTop + area.Y, 16, 16));
            }

            // Render the caption for the tab's content if there's room for it in the tab's content area
            if (_tabContentWidth > (tab.Content.ShowIcon
                ? 16 + IconMarginLeft + IconMarginRight
                : 0) + CaptionMarginLeft + CaptionMarginRight + (tab.ShowCloseButton
                    ? CloseButtonMarginLeft +
                      tab.CloseButtonArea.Width +
                      CloseButtonMarginRight
                    : 0))
            {
                graphicsContext.DrawString(
                    tab.Caption, SystemFonts.CaptionFont, Brushes.Black,
                    new Rectangle(
                        area.X + OverlapWidth + CaptionMarginLeft + (tab.Content.ShowIcon
                            ? IconMarginLeft +
                              16 +
                              IconMarginRight
                            : 0),
                        CaptionMarginTop + area.Y,
                        _tabContentWidth - (tab.Content.ShowIcon
                            ? IconMarginLeft + 16 + IconMarginRight
                            : 0) - (tab.ShowCloseButton
                                ? _closeButtonImage.Width +
                                  CloseButtonMarginRight +
                                  CloseButtonMarginLeft
                                : 0), tab.TabImage.Height),
                    new StringFormat(StringFormatFlags.NoWrap)
                    {
                        Trimming = StringTrimming.EllipsisCharacter
                    });
            }
        }
All Usage Examples Of System.Drawing.Graphics::DrawIcon