protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            int textX = 0;
            if (ShowIcon)
            {
                g.DrawImage(false, _tipIcon, new Point(0, (Height / 2) - (_tipIcon.Height / 2)));
                textX = _tipIcon.Width + 2;
            }

            if (TipText != null)
            {
                TextFormatFlags flags = TextFormatFlags.WordBreak | TextFormatFlags.EndEllipsis;

                // setup text rect
                Rectangle textRectangle = new Rectangle(textX, 0, Width - textX - 3, Height);

                // draw string
                g.DrawText(TipText, Font, textRectangle, Color.FromArgb(GraphicsHelper.Opacity(TextOpacityPct), ForeColor), flags);
            }

        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            Point logoLocation = new Point(HORIZONTAL_INSET, VERTICAL_INSET);
            g.DrawImage(false, _bingLogoBitmap, new Rectangle(logoLocation, _bingLogoBitmap.Size));
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            // draw image
            const int HEADER_X_INSET = 0;
            const int HEADER_Y_INSET = 0;
            g.DrawImage(false, _headerImage, HEADER_X_INSET, HEADER_Y_INSET);

            // draw text centered vertically
            const int TEXT_X_INSET = 5;
            Size textSize = g.MeasureText(_label, Font);
            int textY = (Height / 2) - (textSize.Height / 2);
            Color textColor = !SystemInformation.HighContrast ? Color.FromArgb(0, 77, 131) : SystemColors.WindowText;
            Rectangle textRect = new Rectangle(new Point(HEADER_X_INSET + _headerImage.Width + TEXT_X_INSET, textY), textSize);
            g.DrawText(_label, Font, textRect, textColor);
        }
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs args)
        {
            if (!TabEntry.Hidden)
            {
                //	Call the base class's method so that registered delegates receive the event.
                base.OnPaint(args);

                BidiGraphics g = new BidiGraphics(args.Graphics, VirtualClientRectangle);

                //	Draw the tab.
                DrawTab(g);

                //	Draw the tab bitmap.
                if (!bitmapRectangle.IsEmpty)
                    g.DrawImage(false, TabEntry.TabPageControl.TabBitmap, bitmapRectangle);

                //	Draw tab text.
                if (!textLayoutRectangle.IsEmpty)
                {
                    //	Select the text color to use.
                    Color textColor;
                    if (tabEntry.IsSelected)
                        textColor = TabEntry.TabPageControl.ApplicationStyle.ActiveTabTextColor;
                    else
                        textColor = TabEntry.TabPageControl.ApplicationStyle.InactiveTabTextColor;

                    Rectangle tempRect = textLayoutRectangle;
                    //	Draw the tab text.
                    g.DrawText(TabEntry.TabPageControl.TabText,
                        TabEntry.TabPageControl.ApplicationStyle.NormalApplicationFont,
                        tempRect,
                        textColor,
                        textFormatFlags);
                }
            }

            if (Focused)
                ControlPaint.DrawFocusRectangle(args.Graphics, VirtualClientRectangle, Parent.ForeColor, Parent.BackColor);
        }
        public void PaintBackground(BidiGraphics g)
        {
            // draw watermark if we have one
            if ( WatermarkImage != null && !SystemInformation.HighContrast)
            {

                Point watermarkLocation = new Point(_weblogPanelBody.Bounds.Right - WatermarkImage.Width  , _weblogPanelBody.Bounds.Top  ) ;

                GraphicsContainer gc = g.Graphics.BeginContainer() ;
                try
                {
                    Rectangle clipRegion = _weblogPanelBody.Bounds ;
                    clipRegion.Width -= 1 ;
                    clipRegion.Height -= 1 ;
                    g.IntersectClip(clipRegion);
                    g.DrawImage(false, WatermarkImage, watermarkLocation.X, watermarkLocation.Y);
                }
                finally
                {
                    g.Graphics.EndContainer(gc);
                }

            }
        }
        public void Paint(BidiGraphics g)
        {
            if (_visible && ShowImage)
            {
                if (Image != null)
                {
                    int offset = (Bounds.Height - _image.Height)/2;
                    int y = (_linkLabel.Location.Y + _linkLabel.Height/2) - (_image.Height/2);
                    g.DrawImage(false, _image, Bounds.Location.X, y );
                }

            }
        }
        /// <summary>
        /// Draws a menu item.
        /// </summary>
        /// <param name="drawItemState">A DrawItemEventArgs that contains the event data.</param>
        /// <param name="rect">A DrawItemEventArgs that contains the client rectangle.</param>
        private void DrawMenuItem(DrawItemState drawItemState, Rectangle rect)
        {
            //	Create graphics context on the offscreen bitmap and set the bounds for painting.
            Graphics graphics = Graphics.FromImage(offscreenBitmap);
            graphics.CompositingMode = CompositingMode.SourceOver;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            BidiGraphics g = new BidiGraphics(graphics, new Rectangle(Point.Empty, offscreenBitmap.Size));
            try
            {
                Rectangle bounds = new Rectangle(0, 0, offscreenBitmap.Width, offscreenBitmap.Height);

                //	Fill the menu item with the system-defined menu color.
                g.FillRectangle(SystemBrushes.Menu, bounds);

                //	Fill the bitmap area with the system-defind control color.
                Rectangle bitmapAreaRectangle = new Rectangle(bounds.X,
                                                                bounds.Y,
                                                                STANDARD_BITMAP_AREA_WIDTH,
                                                                bounds.Height);

                //	Fill the background.
                /*
                using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.MenuBitmapAreaColor))
                    graphics.FillRectangle(solidBrush, bitmapAreaRectangle);
                */
                Color backgroundColor = SystemColors.Menu;
                //	If the item is selected, draw the selection rectangle.
                if ((drawItemState & DrawItemState.Selected) != 0)
                {
                    DrawHotlight(g, SystemColors.Highlight, bounds, true);
                    backgroundColor = offscreenBitmap.GetPixel(2, 2);
                }

                //	Obtain the bitmap to draw.  If there is one, draw it centered in the bitmap area.
                Bitmap bitmap = MenuBitmap(drawItemState);
                if (bitmap != null)
                    g.DrawImage(false, bitmap, new Point(
                                                bounds.X + Utility.CenterMinZero(bitmap.Width, bitmapAreaRectangle.Width),
                                                bounds.Y + Utility.CenterMinZero(bitmap.Height, bitmapAreaRectangle.Height)));

                //	Obtain the menu text.  If it's not "-", then this is a menu item.  Otherwise, it's
                //	a separator menu item.
                if (MenuText() != "-")
                {
                    //	Calculate the text area rectangle.  This area excludes an area at the right
                    //	edge of the menu item where the system draws the cascade indicator.  It would
                    //	have been better if MenuItem let us draw the indicator (we did say "OwnerDraw"
                    //	afterall), but this is just how it works.
                    Rectangle textAreaRectangle = new Rectangle(bounds.X + STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING,
                                                                bounds.Y,
                                                                bounds.Width - (STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING + STANDARD_RIGHT_EDGE_PAD),
                                                                bounds.Height);

                    //	Select the brush to draw the menu text with.
                    Color color;
                    if ((drawItemState & DrawItemState.Disabled) == 0)
                        color = SystemColors.MenuText;
                    else
                        color = SystemColors.GrayText;

                    //	Determine the size of the shortcut, if it is being shown.
                    if (!(MenuType == MenuType.Context))
                    {
                        string shortcut;
                        Size shortcutSize;
                        if (ShowShortcut && Shortcut != Shortcut.None)
                        {
                            shortcut = FormatShortcutString(Shortcut);
                            shortcutSize = MeasureShortcutMenuItemText(graphics, shortcut);
                        }
                        else
                        {
                            shortcut = null;
                            shortcutSize = MeasureShortcutMenuItemText(graphics, FormatShortcutString(Shortcut.CtrlIns));
                        }

                        //	Draw the shortcut.
                        if (shortcut != null)
                        {
                            Rectangle shortcutTextRect = textAreaRectangle;
                            TextFormatFlags textFormatTemp = shortcutStringFormat;
                            //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, shortcut, ref stringFormatTemp, ref shortcutTextRect);
                            //	Draw the shortcut text.
                            g.DrawText(shortcut,
                                        menuFont,
                                        shortcutTextRect,
                                        color,
                                        backgroundColor,
                                        textFormatTemp);
                        }

                        //	Reduce the width of the text area rectangle to account for the shortcut and
                        //	the padding before it.
                        textAreaRectangle.Width -= shortcutSize.Width + STANDARD_TEXT_PADDING;
                    }

                    //	Determine which StringFormat to use when drawing the menu item text.
                    TextFormatFlags textFormat;
                    if ((drawItemState & DrawItemState.NoAccelerator) != 0)
                        textFormat = menuItemTextNoHotKeyStringFormat;
                    else
                        textFormat = menuItemTextHotKeyStringFormat;

                    //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, MenuText(), ref stringFormat, ref textAreaRectangle);
                    //	Draw the text.
                    g.DrawText(MenuText(),
                                menuFont,
                                textAreaRectangle,
                                color,
                                backgroundColor,
                                textFormat);
                }
                else
                {
                    //	Calculate the separator line rectangle.  This area excludes an area at the right
                    //	edge of the menu item where the system draws the cascade indicator.  It would
                    //	have been better if MenuItem let us draw the indicator (we did say "OwnerDraw"
                    //	after all), but this is just how it works.
                    Rectangle separatorLineRectangle = new Rectangle(bounds.X + STANDARD_SEPARATOR_PADDING,
                                                                        bounds.Y + Utility.CenterMinZero(1, bounds.Height),
                                                                        bounds.Width - STANDARD_SEPARATOR_PADDING,
                                                                        1);

                    //	Fill the separator line rectangle.
                    g.FillRectangle(SystemBrushes.ControlDark, separatorLineRectangle);
                }
            }
            finally
            {
                //	We're finished with the double buffered painting.  Dispose of the graphics context
                //	and draw the offscreen image.  Cache the offscreen bitmap, though.
                graphics.Dispose();
            }
        }
            public void Paint(BidiGraphics g, Rectangle bounds)
            {
                using (g.Container(bounds.X, bounds.Y))
                {
                    g.Graphics.CompositingMode = CompositingMode.SourceOver;
                    g.Graphics.CompositingQuality = CompositingQuality.HighQuality;

                    using (Font boldFont = new Font(_font, FontStyle.Bold))
                    {
                        Rectangle providerNameRect = new Rectangle(_providerNameLeft, 4, _providerNameWidth, _providerNameHeight);

                        if (_image != null)
                            g.DrawImage(false, _image, (int)(providerNameRect.Left - _image.Width - IMAGE_PADDING_RIGHT), (int)(providerNameRect.Top - 1));

                        g.DrawText(_providerName, boldFont, providerNameRect, Color.White, _textFormatFlags);
                    }

                    g.DrawText(_blogName, _font, new Rectangle(PADDING_LEFT, 23, _blogNameWidth, _providerNameHeight), Color.White, _textFormatFlags);
                }

                // This is down here because DrawIcon has a bug (at least with .NET 1.1) where it
                // doesn't respect any translation transforms that have been applied to the Graphics
                // object in GDI+.
                if (_image == null && _icon != null)
                    g.DrawIcon(false, _icon, new Rectangle(bounds.Left + _imageLeft, bounds.Top + 3, IconWidth, IconHeight));
            }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;
            Rectangle area = e.Bounds;

            e.Graphics.ResetClip();

            BidiGraphics g = new BidiGraphics(e.Graphics, area);

            Image borderImage = null;
            string borderText = "";
            object item = Items[e.Index];
            if (item != null)
                borderText = item.ToString();
            if (item is IComboImageItem)
            {
                IComboImageItem comboItem = (IComboImageItem)item;
                borderImage = comboItem.Image;
            }

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor = SystemColors.Window;
            Color textColor = SystemColors.ControlText;

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter |
                TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, area);
            if (selected && Focused && dropDownShowing)
            {
                //draw the focus highlight rectangle
                Rectangle focusRect = new Rectangle(area.X, area.Y, area.Width - 1, area.Height - 1);
                using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, SystemColors.Highlight)))
                    g.FillRectangle(solidBrush, focusRect);
                using (Pen focusPen = new Pen(SystemColors.Highlight, 1))
                    g.DrawRectangle(focusPen, focusRect);
            }

            // draw border icon
            if (borderImage != null)
            {
                Rectangle imageRect =
                    new Rectangle(area.Left + HORIZONTAL_INSET, area.Top + TOP_INSET, borderImage.Width,
                                  borderImage.Height);
                g.DrawImage(false, borderImage, imageRect);
                //g.DrawRectangle(Pens.Blue, e.Bounds);
            }
            // calculate standard text drawing metrics
            int leftMargin = HORIZONTAL_INSET + MAX_IMAGE_WIDTH + HORIZONTAL_INSET;

            // draw title line
            // post title
            int titleWidth = e.Bounds.Width - leftMargin - 1;
            Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height - 1);
            //g.DrawRectangle(Pens.Red,titleRectangle);
            g.DrawText(
                borderText,
                e.Font, titleRectangle,
                textColor, ellipsesStringFormat);
            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
        private void DrawProviderButton(BidiGraphics g, DrawState drawState)
        {
            // determine the bitmap to draw
            Bitmap buttonBitmap;
            switch (drawState)
            {
                case DrawState.Disabled:
                    buttonBitmap = Command.CommandBarButtonBitmapDisabled;
                    break;
                case DrawState.Enabled:
                    buttonBitmap = Command.CommandBarButtonBitmapEnabled;
                    break;
                case DrawState.Pushed:
                    buttonBitmap = Command.CommandBarButtonBitmapPushed;
                    break;
                case DrawState.Selected:
                    buttonBitmap = Command.CommandBarButtonBitmapSelected;
                    break;
                default:
                    Debug.Fail("Unexpected DrawState!");
                    buttonBitmap = Command.CommandBarButtonBitmapEnabled;
                    break;
            }

            // draw the button
            Rectangle centerButtonInRect;
            if (DropDownContextMenuUserInterface)
                centerButtonInRect = new Rectangle(PROVIDER_HORIZONTAL_PAD, 0, ProviderButtonFaceLeftEnabled.Width, ProviderButtonFaceRightEnabled.Height);
            else if (ContextMenuUserInterface)
                centerButtonInRect = new Rectangle(PROVIDER_HORIZONTAL_PAD, 0, ProviderButtonFaceEnabled.Width, ProviderButtonFaceEnabled.Height);
            else
                centerButtonInRect = new Rectangle(PROVIDER_HORIZONTAL_PAD, 0, ProviderButtonFaceEnabled.Width, ProviderButtonFaceEnabled.Height);

            int left = centerButtonInRect.Left + (centerButtonInRect.Width / 2) - (buttonBitmap.Width / 2) + (drawState == DrawState.Pushed ? 1 : 0);
            int top = centerButtonInRect.Top + (centerButtonInRect.Height / 2) - (buttonBitmap.Height / 2) + (drawState == DrawState.Pushed ? 1 : 0);
            g.DrawImage(false, buttonBitmap, left, top);

            // draw the accompanying arrow if necessary
            Rectangle centerArrowInRect = Rectangle.Empty;
            if (DropDownContextMenuUserInterface)
                centerArrowInRect = new Rectangle(centerButtonInRect.Width, 0, ProviderButtonFaceRightEnabled.Width, ProviderButtonFaceRightEnabled.Height);
            else if (ContextMenuUserInterface)
                centerArrowInRect = new Rectangle(centerButtonInRect.Width - 1, 0, ProviderButtonFaceDropDownEnabled.Width - ProviderButtonFaceEnabled.Width, ProviderButtonFaceDropDownEnabled.Height);
            if (centerArrowInRect != Rectangle.Empty)
            {
                int arrowLeft = centerArrowInRect.Left + (centerArrowInRect.Width / 2) - (ProviderDownArrow.Width / 2) + (ContextMenuShowing ? 1 : 0);
                int arrowTop = centerArrowInRect.Top + (centerArrowInRect.Height / 2) - (ProviderDownArrow.Height / 2) + (ContextMenuShowing ? 1 : 0);
                g.DrawImage(true, ProviderDownArrow, arrowLeft, arrowTop);
            }
        }
 private void DrawProviderButtonFace(BidiGraphics g, DrawState drawState)
 {
     if (DropDownContextMenuUserInterface)
     {
         if (drawState == DrawState.Selected)
         {
             g.DrawImage(true, ProviderButtonFaceLeftEnabled, PROVIDER_HORIZONTAL_PAD, 0);
             if (ContextMenuShowing)
                 g.DrawImage(true, ProviderButtonFaceRightPressed, PROVIDER_HORIZONTAL_PAD + ProviderButtonFaceLeftEnabled.Width, 0);
             else
                 g.DrawImage(true, ProviderButtonFaceRightEnabled, PROVIDER_HORIZONTAL_PAD + ProviderButtonFaceLeftEnabled.Width, 0);
         }
         else if (drawState == DrawState.Pushed)
         {
             if (ContextMenuShowing)
             {
                 g.DrawImage(true, ProviderButtonFaceLeftEnabled, PROVIDER_HORIZONTAL_PAD, 0);
                 g.DrawImage(true, ProviderButtonFaceRightPressed, PROVIDER_HORIZONTAL_PAD + ProviderButtonFaceLeftEnabled.Width, 0);
             }
             else
             {
                 g.DrawImage(true, ProviderButtonFaceLeftPressed, PROVIDER_HORIZONTAL_PAD, 0);
                 g.DrawImage(true, ProviderButtonFaceRightPressed, PROVIDER_HORIZONTAL_PAD + ProviderButtonFaceLeftEnabled.Width, 0);
             }
         }
     }
     else if (ContextMenuUserInterface)
     {
         if (drawState == DrawState.Selected)
             g.DrawImage(true, ProviderButtonFaceDropDownEnabled, PROVIDER_HORIZONTAL_PAD, 0);
         else if (drawState == DrawState.Pushed)
             g.DrawImage(true, ProviderButtonFaceDropDownPressed, PROVIDER_HORIZONTAL_PAD, 0);
     }
     else
     {
         if (drawState == DrawState.Selected)
             g.DrawImage(true, ProviderButtonFaceEnabled, PROVIDER_HORIZONTAL_PAD, 0);
         else if (drawState == DrawState.Pushed)
             g.DrawImage(true, ProviderButtonFacePressed, PROVIDER_HORIZONTAL_PAD, 0);
     }
 }
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs args)
        {
            //	Call the base class's method so that registered delegates receive the event.
            base.OnPaint(args);

            // Fix bug 602576: The 'Remove Effects' button is truncated in right-to-left builds
            if (BidiHelper.IsRightToLeft)
                args.Graphics.ResetClip();

            // Take int account vertical padding
            Rectangle rect = new Rectangle(VirtualClientRectangle.X, VirtualClientRectangle.Y + VerticalPadding, VirtualClientRectangle.Width, VirtualClientRectangle.Height);

            BidiGraphics g = new BidiGraphics(args.Graphics, rect);

            //	No painting required if there is no parent or no command.
            if (Parent == null || Command == null)
                return;

            //	Determine the draw state of the button.
            DrawState drawState;
            if (!Command.Enabled)
                drawState = DrawState.Disabled;
            else if (Command.Latched || (ButtonPushed && MouseInside) || (ContextMenuUserInterface && ContextMenuShowing))
                drawState = DrawState.Pushed;
            else if (MouseInside || (DropDownContextMenuUserInterface && ContextMenuShowing))
                drawState = DrawState.Selected;
            else
                drawState = DrawState.Enabled;

            //	Draw the button.
            if (Command.CommandBarButtonStyle == CommandBarButtonStyle.System)
            {
                Size imageSize = ImageSize;

                // is this a large button?
                bool isLargeButton = false;
                if (imageSize.Height > SystemButtonHelper.SMALL_BUTTON_IMAGE_SIZE)
                    isLargeButton = true;

                if (Command is ICustomButtonBitmapPaint)
                {
                    switch (drawState)
                    {
                        case DrawState.Selected:
                            SystemButtonHelper.DrawSystemButtonFace(g, DropDownContextMenuUserInterface, contextMenuShowing, VirtualClientRectangle, isLargeButton);
                            break;
                        case DrawState.Pushed:
                            SystemButtonHelper.DrawSystemButtonFacePushed(g, DropDownContextMenuUserInterface, VirtualClientRectangle, isLargeButton);
                            break;
                    }

                    ((ICustomButtonBitmapPaint)Command).Paint(g, rImage, drawState);
                }
                else
                {
                    Bitmap buttonBitmap = null;
                    switch (drawState)
                    {
                        case DrawState.Disabled:
                            buttonBitmap = Command.CommandBarButtonBitmapDisabled;
                            break;
                        case DrawState.Enabled:
                            buttonBitmap = Command.CommandBarButtonBitmapEnabled;
                            break;
                        case DrawState.Selected:
                            SystemButtonHelper.DrawSystemButtonFace(g, DropDownContextMenuUserInterface, contextMenuShowing, VirtualClientRectangle, isLargeButton);
                            buttonBitmap = Command.CommandBarButtonBitmapSelected;
                            break;
                        case DrawState.Pushed:
                            SystemButtonHelper.DrawSystemButtonFacePushed(g, DropDownContextMenuUserInterface, VirtualClientRectangle, isLargeButton);
                            buttonBitmap = Command.CommandBarButtonBitmapSelected;
                            break;
                    }

                    //	Draw the button bitmap.
                    if (buttonBitmap != null && !Command.SuppressCommandBarBitmap)
                    {
                        if (!SystemInformation.HighContrast)
                            g.DrawImage(false, buttonBitmap, rImage);
                        else
                        {
                            //apply a high contrast image matrix
                            ImageAttributes ia = new ImageAttributes();
                            ia.SetColorMatrix(HighContrastColorMatrix);
                            ColorMap cm = new ColorMap();
                            cm.OldColor = Color.White;
                            cm.NewColor = SystemColors.Control;
                            ia.SetRemapTable(new ColorMap[] { cm });
                            g.DrawImage(false, buttonBitmap, rImage, 0, 0, buttonBitmap.Width, buttonBitmap.Height, GraphicsUnit.Pixel, ia);
                        }
                    }
                }

                //	Draw the text.
                if (Command.CommandBarButtonText != null && Command.CommandBarButtonText.Length != 0)
                {
                    Color textColor;
                    if (drawState == DrawState.Disabled)
                        textColor = commandBarLightweightControl.DisabledTextColor;
                    else
                        textColor = commandBarLightweightControl.TextColor;

                    g.DrawText(
                        Command.CommandBarButtonText,
                        ApplicationManager.ApplicationStyle.NormalApplicationFont,
                        rText,
                        textColor,
                        TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.NoPadding | TextFormatFlags.NoClipping);
                }

                //	Draw the context menu arrow, if needed.
                if (DropDownContextMenuUserInterface || ContextMenuUserInterface)
                {
                    Bitmap contextMenuArrowBitmapToDraw;
                    if (drawState == DrawState.Disabled)
                        contextMenuArrowBitmapToDraw = contextMenuArrowBitmapDisabled;
                    else
                        contextMenuArrowBitmapToDraw = contextMenuArrowBitmap;

                    int height = isLargeButton ? SystemButtonHelper.LARGE_BUTTON_TOTAL_SIZE : VirtualHeight;
                    g.DrawImage(false, contextMenuArrowBitmapToDraw, rArrow);
                }
            }
            else if (Command.CommandBarButtonStyle == CommandBarButtonStyle.Bitmap)
            {
                switch (drawState)
                {
                    case DrawState.Disabled:
                        g.DrawImage(true, Command.CommandBarButtonBitmapDisabled, HorizontalMargin, TOP_MARGIN);
                        break;
                    case DrawState.Enabled:
                        g.DrawImage(true, Command.CommandBarButtonBitmapEnabled, HorizontalMargin, TOP_MARGIN);
                        break;
                    case DrawState.Selected:
                        g.DrawImage(true, Command.CommandBarButtonBitmapSelected, HorizontalMargin, TOP_MARGIN);
                        break;
                    case DrawState.Pushed:
                        g.DrawImage(true, Command.CommandBarButtonBitmapPushed, HorizontalMargin, TOP_MARGIN);
                        break;
                }
            }
            else if (Command.CommandBarButtonStyle == CommandBarButtonStyle.Provider)
            {
                DrawProviderButtonFace(g, drawState);
                DrawProviderButton(g, drawState);
            }

            if (Focused)
                g.DrawFocusRectangle(new Rectangle(0, 0, VirtualWidth, VirtualHeight), Parent.ForeColor, Parent.BackColor);
        }
Esempio n. 13
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //	Call the base class's method so that registered delegates receive the event.
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            //	Determine the draw state of the button.
            DrawState drawState;
            if (!Enabled)
                drawState = DrawState.Disabled;
            else if (Latched)
                drawState = DrawState.Latched;
            else if (Pushed && MouseInside)
                drawState = DrawState.Pushed;
            else if (MouseInside)
                drawState = DrawState.Selected;
            else
                drawState = DrawState.Enabled;

            //	Draw the button face, as needed, and select the button bitmap to draw below.
            Bitmap buttonBitmap = null;
            switch (drawState)
            {
                case DrawState.Disabled:
                    buttonBitmap = BitmapDisabled;
                    break;

                case DrawState.Enabled:
                    if (Focused)
                    {
                        if (ButtonStyle == ButtonStyle.Standard)
                            DrawStandardButtonFace(e.Graphics);
                        else if (ButtonStyle == ButtonStyle.Flat)
                            DrawFlatButtonFace(e.Graphics);
                    }

                    buttonBitmap = BitmapEnabled;
                    break;

                case DrawState.Selected:
                    if (ButtonStyle == ButtonStyle.Standard)
                        DrawStandardButtonFace(e.Graphics);
                    else if (ButtonStyle == ButtonStyle.Flat)
                        DrawFlatButtonFace(e.Graphics);
                    buttonBitmap = BitmapSelected;
                    break;

                case DrawState.Latched:
                case DrawState.Pushed:
                    if (ButtonStyle == ButtonStyle.Standard)
                    {
                        DrawStandardButtonFacePushed(e.Graphics);
                        buttonBitmap = BitmapSelected;
                    }
                    else if (ButtonStyle == ButtonStyle.Flat)
                    {
                        DrawFlatButtonFacePushed(e.Graphics);
                        buttonBitmap = BitmapSelected;
                    }
                    else if (ButtonStyle == ButtonStyle.Bitmap)
                        buttonBitmap = BitmapPushed;
                    break;
            }

            //	Draw the button bitmap, if there is one.
            if (buttonBitmap != null)
            {
                //	Set the rectangle into which we'll draw the bitmap.
                Rectangle drawBitmapRectangle = bitmapRectangle;
                //				if (ButtonStyle != ButtonStyle.Bitmap && drawState == DrawState.Pushed)
                //					drawBitmapRectangle.Offset(ScaleX(PUSHED_OFFSET), ScaleY(PUSHED_OFFSET));

                //	Draw the bitmap.
                g.DrawImage(AllowMirroring, buttonBitmap, new Rectangle(ScaleX(drawBitmapRectangle.X), ScaleY(drawBitmapRectangle.Y), ScaleX(buttonBitmap.Width), ScaleY(buttonBitmap.Height)));
            }

            //	If focus is being shown, and we're focused, draw the focus rectangle.
            if (ShowFocusCues && Focused)
            {
                Rectangle rectangle = ClientRectangle;
                if (ButtonStyle == ButtonStyle.Flat)
                {
                    //offset the focus a bit to ensure it draws directly over the flat border
                    rectangle = new Rectangle(rectangle.Location, new Size(ScaleX(rectangle.Width - 1), ScaleY(rectangle.Height - 1)));

                    //clear the background of the rectangle so it contrasts well with the flat selection
                    using (Pen p = new Pen(BackColor))
                        g.DrawRectangle(p, rectangle);
                }

                ControlPaint.DrawFocusRectangle(e.Graphics, rectangle);
            }

            //	Draw the button text, if there is some.
            if (ButtonStyle != ButtonStyle.Bitmap && buttonText != null)
            {
                //	Set the rectangle into which we'll draw the text.
                Rectangle drawTextRectangle = textRectangle;
                drawTextRectangle.Offset(HORIZONTAL_TEXT_PAD, VERTICAL_TEXT_PAD);
                if (drawState == DrawState.Pushed)
                    drawTextRectangle.Offset(ScaleX(PUSHED_OFFSET), ScaleY(PUSHED_OFFSET));

                TextFormatFlags textFormat;
                if (ShowKeyboardCues)
                    textFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.EndEllipsis;
                else
                    textFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.EndEllipsis | TextFormatFlags.HidePrefix;

                //	Set the text color.
                Color textColor = ForeColor;
                if (!Enabled)
                    textColor = Color.FromArgb(GraphicsHelper.Opacity(50), textColor);

                //	Draw the text.
                g.DrawText(buttonText,
                                Font,
                                drawTextRectangle,
                                textColor,
                                textFormat);
            }
        }
        public static void DrawErrorMockPlayer(Bitmap img, BidiGraphics bidiGraphics, string message)
        {
            int LEFT_PADDING = 30;
            int RIGHT_PADDING = 10;
            int ERROR_IMAGE_WIDTH = 32;
            int ERROR_IMAGE_HEIGHT = 32;
            int IMAGE_TO_TEXT_PADDING = 7;
            int PLACEHOLDER_HEIGHT = img.Height;
            int PLACEHOLDER_WIDTH = img.Width;
            int VERTICAL_OFFSET = 30;
            int LINE_BREAK_PADDING = 4;

            Size titleSize = bidiGraphics.MeasureText(Res.Get(StringId.VideoError),
                                          Res.GetFont(FontSize.XXLarge, FontStyle.Bold),
                                          new Size(PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING, PLACEHOLDER_HEIGHT - VERTICAL_OFFSET),
                                          TextFormatFlags.WordBreak);

            bidiGraphics.DrawText(Res.Get(StringId.VideoError),
                                  Res.GetFont(FontSize.XXLarge,
                                  FontStyle.Bold),
                                  new Rectangle(LEFT_PADDING + ERROR_IMAGE_WIDTH + IMAGE_TO_TEXT_PADDING,
                                                VERTICAL_OFFSET + (ERROR_IMAGE_HEIGHT / 2) - (titleSize.Height / 2),
                                                PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING,
                                                PLACEHOLDER_HEIGHT - VERTICAL_OFFSET),
                                  Color.White,
                                  TextFormatFlags.WordBreak);

            bidiGraphics.DrawText(message,
                                  Res.GetFont(FontSize.XLarge,
                                  FontStyle.Regular),
                                  new Rectangle(LEFT_PADDING + ERROR_IMAGE_WIDTH + IMAGE_TO_TEXT_PADDING,
                                                VERTICAL_OFFSET + (ERROR_IMAGE_HEIGHT / 2) - (titleSize.Height / 2) + titleSize.Height + LINE_BREAK_PADDING,
                                                PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING,
                                                PLACEHOLDER_HEIGHT - (VERTICAL_OFFSET + titleSize.Height + LINE_BREAK_PADDING)),
                                  Color.White,
                                  TextFormatFlags.WordBreak);

            bidiGraphics.DrawImage(false,
                       ResourceHelper.LoadAssemblyResourceBitmap("Video.Images.Error.gif"),
                       LEFT_PADDING,
                       VERTICAL_OFFSET);
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;

            // get post we are rendering
            PostInfo postInfo = (Items[e.Index] as PostInfoItem).PostInfo;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;
            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.NoPrefix;

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            // draw top-line if necessary
            //if ( !selected )
            {
                using (Pen pen = new Pen(_theme.topLineColor))
                    g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - ScaleY(1));
            }

            // draw post icon
            g.DrawImage(false, _blogPostImage, new Rectangle(
                                  e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(TITLE_INSET),
                                  ScaleX(_blogPostImage.Width), ScaleY(_blogPostImage.Height)));

            // calculate standard text drawing metrics
            int leftMargin = ScaleX(HORIZONTAL_INSET) + ScaleX(_blogPostImage.Width) + ScaleX(HORIZONTAL_INSET);
            int topMargin = e.Bounds.Top + ScaleY(TITLE_INSET);
            // draw title line

            // post date
            string dateText = postInfo.PrettyDateDisplay;
            Size dateSize = g.MeasureText(dateText, e.Font);
            Rectangle dateRectangle = new Rectangle(
                e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - dateSize.Width, topMargin, dateSize.Width, dateSize.Height);

            g.DrawText(dateText, e.Font, dateRectangle, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix);

            // post title
            int titleWidth = dateRectangle.Left - leftMargin - ScaleX(DATE_PADDING);
            string titleString = String.Format(CultureInfo.CurrentCulture, "{0}", postInfo.Title);
            int fontHeight = g.MeasureText(titleString, e.Font).Height;
            Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight);

            g.DrawText(
                titleString,
                e.Font,
                titleRectangle, textColor, ellipsesStringFormat);

            // draw post preview

            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                leftMargin,
                topMargin + fontHeight + ScaleY(PREVIEW_INSET),
                e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET),
                fontHeight * PREVIEW_LINES);

            // draw post preview
            string postPreview = postInfo.PlainTextContents;
            if (PostSource.HasMultipleWeblogs && (postInfo.BlogName != String.Empty))
                postPreview = String.Format(CultureInfo.CurrentCulture, "{0} - {1}", postInfo.BlogName, postPreview);

            g.DrawText(
                postPreview,
                e.Font, layoutRectangle, textColor, ellipsesStringFormat);

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
        // replace standard painting behavior
        protected override void OnDrawItem(DrawItemEventArgs evt)
        {
            BidiGraphics g = new BidiGraphics(evt.Graphics, ClientRectangle);

            // determine the text color based on whether we have categories
            bool hasCategories = _categoryContext.SelectedCategories.Length > 0;
            Color textColor = hasCategories ? SystemColors.ControlText : SystemColors.GrayText; //Color.FromArgb(200, SystemColors.ControlText) ;

            // margins
            const int HORIZONTAL_MARGIN = 1;

            // draw the icon (if we have one)
            const int ICON_MARGIN = 4;
            int textMargin = 0;
            if (_icon != null)
            {
                g.DrawImage(true, _icon, new Rectangle(ScaleX(ICON_MARGIN), ScaleY(2), ScaleX(_icon.Width), ScaleY(_icon.Height)));
                textMargin += ScaleX(ICON_MARGIN + _icon.Width);
            }

            // draw the text
            int leftMargin = textMargin;
            int rightMargin = ScaleX(HORIZONTAL_MARGIN);
            Rectangle textRegion = new Rectangle(new Point(leftMargin, -1), new Size(Width - leftMargin - rightMargin, Height));

            TextFormatFlags tempFormat = DisplayFormat;
            Rectangle tempRectangle = textRegion;

            g.DrawText(
                _categoryContext.Text,
                Font, tempRectangle, textColor, tempFormat);

            // draw focus rectangle (only if necessary)
            evt.DrawFocusRectangle();
        }
Esempio n. 17
0
        private Size Render(BidiGraphics g, int width, int height)
        {
            int maxWidth = 0;
            // Start at the top left after padding
            Point origin = new Point(HORIZONTAL_PADDING, VERTICAL_PADDING);

            // Draw the green arrow
            Image arrow;
            if (IsHovered)
                arrow = ResourceHelper.LoadAssemblyResourceBitmap("Images.arrow_hover.png");
            else
                arrow = ResourceHelper.LoadAssemblyResourceBitmap("Images.arrow.png");
            if (g != null)
                g.DrawImage(true, arrow, origin.X, origin.Y + 3);
            origin.Offset(arrow.Width + HORIZONTAL_PADDING, 0);

            TextFormatFlags textFormatFlags = TextFormatFlags.NoPadding | TextFormatFlags.WordBreak;

            // Draw the Heading
            Size headingMaxSize = new Size(width - origin.X - HORIZONTAL_PADDING - 1, height - origin.Y - VERTICAL_PADDING);
            if (g == null)
            {
                headingSize = TextRenderer.MeasureText(Heading, Res.GetFont(FontSize.XLarge, FontStyle.Regular),
                                         headingMaxSize, textFormatFlags);
            }
            else
            {
                g.DrawText(Heading, Res.GetFont(FontSize.XLarge, FontStyle.Regular), new Rectangle(new Point(origin.X - 1, origin.Y), headingMaxSize), ChoiceDialog.BlueText, textFormatFlags);
            }
            origin.Offset(0, headingSize.Height + INSIDE_VERTICAL_PADDING);
            maxWidth = headingSize.Width;

            // Draw the subheading
            if (!string.IsNullOrEmpty(SubHeading))
            {
                if (g == null)
                {
                    subHeadingSize = TextRenderer.MeasureText(SubHeading, Res.DefaultFont,
                         new Size(width - origin.X - HORIZONTAL_PADDING, height - origin.Y), textFormatFlags | TextFormatFlags.NoPrefix);

                }
                else
                {
                    g.DrawText(SubHeading, Res.DefaultFont, new Rectangle(origin.X, origin.Y, width - origin.X - HORIZONTAL_PADDING, height - origin.Y), ChoiceDialog.BlueText, textFormatFlags | TextFormatFlags.NoPrefix);
                }
                maxWidth = Math.Max(subHeadingSize.Width, maxWidth);
                origin.Offset(0, subHeadingSize.Height + INSIDE_VERTICAL_PADDING);

            }

            // Draw the image
            if (OptionImage != null)
            {
                if (g != null)
                {
                    g.DrawImage(false, OptionImage, origin);
                }
                origin.Offset(0, OptionImage.Height);
                maxWidth = Math.Max(OptionImage.Width, maxWidth);
            }

            origin.Offset(maxWidth + HORIZONTAL_PADDING, VERTICAL_PADDING);
            return new Size(origin);
        }
        private static void TileFillScaledImageHorizontally(BidiGraphics graphics, Image image, Rectangle rectangle, Rectangle srcRectangle)
        {
            for (int x = rectangle.X; x < rectangle.Right; x += srcRectangle.Width)
                graphics.DrawImage(true,
                                    image,
                                       new Rectangle(x, rectangle.Y, Math.Min(srcRectangle.Width, rectangle.Right - x), rectangle.Height),
                                       srcRectangle,
                                       GraphicsUnit.Pixel);

        }
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //	Call the base class's method so that registered delegates receive the event.
            base.OnPaint(e);

            Graphics g = e.Graphics;

            //	Obtain the bitmap to draw and, if there is one, draw it.
            Bitmap bitmap = BitmapToDraw;
            if (bitmap != null)
            {
                //	Fill the offscreen graphics context with the background color.
                if (UseVirtualTransparency)
                {
                    VirtualTransparency.VirtualPaint(this, new PaintEventArgs(g, ClientRectangle));
                }
                else
                {
                    using (SolidBrush solidBrush = new SolidBrush(BackColor))
                        g.FillRectangle(solidBrush, ClientRectangle);
                }

                BidiGraphics bg = new BidiGraphics(g, ClientRectangle, RightToLeft);
                Rectangle bounds = new Rectangle(Point.Empty, bitmap.Size);
                bg.DrawImage(true, bitmap, bounds);
            }
        }
        // Slow. Use OpenLiveWriter.CoreServices.UI.BorderPaint if performance matters
        public static void DrawLeftCenterRightImageBorder(
            BidiGraphics graphics,
            Rectangle rectangle,
            Image image,
            Rectangle leftSlice,
            Rectangle centerSlice,
            Rectangle rightSlice)
        {
            GraphicsContainer graphicsContainer = graphics.Graphics.BeginContainer();
            // Have to remove this line because it messes with mirrored images.
            //   Specifically, right-to-left drawing of the hover effect for the context menu dongle
            //   hanging off "Save Draft" doesn't happen at all. Seems like a short-circuit happens
            //   in Graphics when the image's location is outside the clipping area.
            //graphics.Graphics.SetClip(rectangle);
            graphics.Graphics.CompositingMode = CompositingMode.SourceOver;
            graphics.Graphics.CompositingQuality = CompositingQuality.HighQuality;

            graphics.DrawImage(
                true,
                image,
                new Rectangle(rectangle.Left, rectangle.Top, leftSlice.Width, rectangle.Height),
                leftSlice.Left, leftSlice.Top, leftSlice.Width, leftSlice.Height,
                GraphicsUnit.Pixel
                );
            TileFillScaledImageHorizontally(
                graphics,
                image,
                new Rectangle(rectangle.Left + leftSlice.Width, rectangle.Top, Math.Max(0, rectangle.Width - leftSlice.Width - rightSlice.Width), rectangle.Height),
                centerSlice);
            graphics.DrawImage(
                true,
                image,
                new Rectangle(rectangle.Right - rightSlice.Width, rectangle.Top, rightSlice.Width, rectangle.Height),
                rightSlice.Left, rightSlice.Top, rightSlice.Width, rightSlice.Height,
                GraphicsUnit.Pixel
                );

            graphics.Graphics.EndContainer(graphicsContainer);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, _controlRectangle);

            Color backgroundColor = ColorizedResources.Instance.SidebarGradientBottomColor;
            using (Brush brush = new SolidBrush(backgroundColor))
                g.FillRectangle(brush, _controlRectangle);

            if (!(_image == null && (Text == null || Text == string.Empty)))
            {
                // draw the border
                using (Pen pen = new Pen(ColorizedResources.Instance.BorderLightColor))
                {
                    g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Top, _controlRectangle.Width, _controlRectangle.Top);
                    g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Bottom, _controlRectangle.Width, _controlRectangle.Bottom);
                }

                // draw the image
                if (_image != null)
                    g.DrawImage(true, _image, new Rectangle(_imageRectangle.Left, _imageRectangle.Top, _image.Width, _image.Height));

                // draw the text
                g.DrawText(Text, ApplicationManager.ApplicationStyle.NormalApplicationFont,
                                       new Rectangle(_textRectangle.X, _textRectangle.Y, _textRectangle.Width, _textRectangle.Height),
                                       ApplicationManager.ApplicationStyle.PrimaryWorkspaceCommandBarTextColor,
                                       _stringFormat);
            }
        }
Esempio n. 22
0
        private Bitmap CreateBitmap()
        {
            Bitmap bitmap = new Bitmap(_backgroundImage.Width, _backgroundImage.Height, PixelFormat.Format32bppArgb);
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                BidiGraphics g = new BidiGraphics(graphics, bitmap.Size);

                // draw transparent background image
                g.DrawImage(false, _backgroundImage,
                            new Rectangle(0, 0, _backgroundImage.Width, _backgroundImage.Height));

                // draw logo image
                g.DrawImage(false, _logoImage, new Rectangle(
                    (ClientSize.Width - _logoImage.Width) / 2,
                    120 - _logoImage.Height,
                    _logoImage.Width,
                    _logoImage.Height));

                // draw copyright notice
                string splashText = Res.Get(StringId.SplashScreenCopyrightNotice);
                using (Font font = new Font(Font.FontFamily, 7.5f))
                {
                    const int TEXT_PADDING_H = 36;
                    const int TEXT_PADDING_V = 26;
                    int textWidth = Size.Width - 2 * TEXT_PADDING_H;
                    int textHeight =
                        Convert.ToInt32(
                            g.MeasureText(splashText, font, new Size(textWidth, 0), TextFormatFlags.WordBreak).Height,
                            CultureInfo.InvariantCulture);

                    // GDI text can't be drawn on an alpha-blended surface. So we render a black-on-white
                    // bitmap, then use a ColorMatrix to effectively turn it into an alpha mask.

                    using (Bitmap textBitmap = new Bitmap(textWidth, textHeight, PixelFormat.Format32bppRgb))
                    {
                        using (Graphics tbG = Graphics.FromImage(textBitmap))
                        {
                            tbG.FillRectangle(Brushes.Black, 0, 0, textWidth, textHeight);
                            new BidiGraphics(tbG, textBitmap.Size).
                                DrawText(splashText, font, new Rectangle(0, 0, textWidth, textHeight), Color.White, Color.Black, TextFormatFlags.WordBreak);
                        }

                        Rectangle textRect = new Rectangle(TEXT_PADDING_H, ClientSize.Height - TEXT_PADDING_V - textHeight, textWidth, textHeight);
                        using (ImageAttributes ia = new ImageAttributes())
                        {
                            ColorMatrix cm = new ColorMatrix(new float[][]
                                                                 {
                                                                     new float[] {0, 0, 0, 1f/3f, 0},
                                                                     new float[] {0, 0, 0, 1f/3f, 0},
                                                                     new float[] {0, 0, 0, 1f/3f, 0},
                                                                     new float[] {0, 0, 0, 0, 0},
                                                                     new float[] {0.9372f, 0.9372f, 0.9372f, 0, 0},
                                                                 });
                            ia.SetColorMatrix(cm);
                            g.DrawImage(false, textBitmap, textRect, 0, 0, textWidth, textHeight, GraphicsUnit.Pixel, ia);
                        }
                    }
                }
            }
            return bitmap;
        }
        /// <summary>
        /// Raises the DrawItem event.
        /// </summary>
        /// <param name="e">A DrawItemEventArgs that contains the event data.</param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            //	Call the base class's method.
            base.OnDrawItem(e);

            //	Do the menu hack.
            MenuHack(e);

            //	Draw the menu item.
            if (Parent is MainMenu)
            {
                DrawMainMenuItem(e);
                //	Draw the offscreen bitmap.
                //BidiGraphics g = new BidiGraphics(e.Graphics, new Size(GetMainMenu().GetForm().Width, e.Bounds.Height));
                //g.DrawImage(false, offscreenBitmap, e.Bounds.Location);

            }
            else
            {
                //	If we have an offscreen bitmap, and it's the wrong size, dispose of it.
                //  Add try/catch due to lots of Watson-reported crashes here
                //    on offscreenBitmap.Size ("object is in use elsewhere" yadda yadda)
                try
                {
                    if (offscreenBitmap != null && offscreenBitmap.Size != e.Bounds.Size)
                    {
                        offscreenBitmap.Dispose();
                        offscreenBitmap = null;
                    }
                }
                catch (Exception ex)
                {
                    Trace.Fail(ex.ToString());
                    offscreenBitmap = null;
                }

                //	Allocate the offscreen bitmap, if we don't have one cached.
                if (offscreenBitmap == null)
                    offscreenBitmap = new Bitmap(e.Bounds.Width, e.Bounds.Height);

                DrawMenuItem(e.State, e.Bounds);
                //	Draw the offscreen bitmap.
                BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);
                //in the main menu drop downs, the highlight rectangle is off by one
                Point location = e.Bounds.Location;
                if (e.Graphics.VisibleClipBounds.X == -1.0)
                    location.X += 1;

                g.DrawImage(false, offscreenBitmap, location);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);
            // draw icon
            if (_domainImage != null)
                g.DrawImage(false, _domainImage, new Rectangle(0, 0, _domainImageSize.Width, _domainImageSize.Height));
            else if (_domainIcon != null)
                g.DrawIcon(false, _domainIcon, new Rectangle(0, 0, _domainImageSize.Width, _domainImageSize.Height));
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;

            // get post-source we are rendering
            IPostEditorPostSource postSource = (Items[e.Index] as PostSourceItem).PostSource;

            // determine image and text to use
            Image postSourceImage;
            if (e.Index == _draftsIndex)
                postSourceImage = _showLargeIcons ? _draftsImageLarge : _draftsImage;
            else if (e.Index == _recentPostsIndex)
                postSourceImage = _showLargeIcons ? _recentPostsImageLarge : _recentPostsImage;
            else
                postSourceImage = _showLargeIcons ? _weblogImageLarge : _weblogImage;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;
            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            if (_showLargeIcons)
            {
                // center the image within the list box
                int imageLeft = e.Bounds.Left + ((e.Bounds.Width / 2) - (ScaleX(postSourceImage.Width) / 2));
                int imageTop = e.Bounds.Top + ScaleY(LARGE_TOP_INSET);
                g.DrawImage(false, postSourceImage, new Rectangle(imageLeft, imageTop, ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

                // setup string format
                TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.HorizontalCenter;

                // calculate standard text drawing metrics
                int leftMargin = ScaleX(ELEMENT_PADDING);
                int topMargin = imageTop + ScaleY(postSourceImage.Height) + ScaleY(ELEMENT_PADDING);
                int fontHeight = g.MeasureText(postSource.Name, e.Font).Height;

                // caption
                // calculate layout rectangle
                Rectangle layoutRectangle = new Rectangle(
                    leftMargin,
                    topMargin,
                    e.Bounds.Width - (2 * ScaleX(ELEMENT_PADDING)),
                    fontHeight * TITLE_LINES);

                // draw caption
                g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat);

            }
            else
            {
                // draw post icon
                g.DrawImage(false, postSourceImage,
                                      new Rectangle(e.Bounds.Left + ScaleX(ELEMENT_PADDING), e.Bounds.Top + ScaleY(SMALL_TOP_INSET),
                                      ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

                // setup string format
                TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;

                // calculate standard text drawing metrics
                int leftMargin = ScaleX(ELEMENT_PADDING) + ScaleX(postSourceImage.Width) + ScaleX(ELEMENT_PADDING);
                int topMargin = e.Bounds.Top + ScaleY(SMALL_TOP_INSET);
                int fontHeight = g.MeasureText(postSource.Name, e.Font).Height;

                // caption
                // calculate layout rectangle
                Rectangle layoutRectangle = new Rectangle(
                    leftMargin,
                    topMargin,
                    e.Bounds.Width - leftMargin - ScaleX(ELEMENT_PADDING),
                    fontHeight * TITLE_LINES);

                // draw caption
                g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat);
            }

            // draw focus rectange if necessary
            e.DrawFocusRectangle();
        }
Esempio n. 26
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);
            if (m_pressed)
            {
                SystemButtonHelper.DrawSystemButtonFacePushed(g, false, ClientRectangle, false);
            }
            else if (m_hover)
            {
                SystemButtonHelper.DrawSystemButtonFace(g, false, false, ClientRectangle, false);
            }

            Rectangle colorRect = new Rectangle(PADDING, PADDING, COLOR_SIZE, COLOR_SIZE);
            Rectangle dropDownArrowRect = new Rectangle(Width - PADDING - m_dropDownArrow.Width,
                                                        PADDING,
                                                        m_dropDownArrow.Width,
                                                        colorRect.Height);
            Rectangle textRect = new Rectangle(PADDING + GUTTER_SIZE + colorRect.Width,
                PADDING,
                Width - (PADDING + GUTTER_SIZE + colorRect.Width) - (PADDING + GUTTER_SIZE + dropDownArrowRect.Width),
                colorRect.Height);

            using (Brush b = new SolidBrush(EffectiveColor))
                g.FillRectangle(b, colorRect);
            using (Pen p = new Pen(SystemColors.Highlight, 1))
                g.DrawRectangle(p, colorRect);

            g.DrawText(Text, Font, textRect, SystemColors.ControlText, ShowKeyboardCues ? TextFormatFlags.Default : TextFormatFlags.NoPrefix);

            g.DrawImage(false,
                        m_dropDownArrow,
                        RectangleHelper.Center(m_dropDownArrow.Size, dropDownArrowRect, false),
                        0,
                        0,
                        m_dropDownArrow.Width,
                        m_dropDownArrow.Height,
                        GraphicsUnit.Pixel);
        }
        public void Paint(BidiGraphics g)
        {
            // draw icon
            if ( Image != null )
                g.DrawImage(false, Image, Bounds.X, Bounds.Y) ;
            else if ( Icon != null )
                g.DrawIcon(false, Icon, Bounds.X, Bounds.Y);

            // draw text
            g.DrawText(Caption, _captionFont, new Rectangle(CaptionBounds.X, CaptionBounds.Y, CaptionBounds.Width, CaptionBounds.Height), SystemColors.ControlText, TextFormatFlags.WordEllipsis );
        }
 /// <summary>
 /// Draw the thumbnail by rendering the image in the provided bounds
 /// </summary>
 public virtual void Draw(BidiGraphics g, Font font, Rectangle thumbnailRect)
 {
     g.DrawImage(false, Image, thumbnailRect);
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, _controlRect);

            //draw the splitter line
            GraphicsHelper.TileFillScaledImageHorizontally(g, extendedEntrySeparatorTileImage, _lineRect);

            //draw the More... box
            Color backgroundColor = Color.FromArgb(128, 128, 128);
            SizeF moreTextSize = g.MeasureText(_moreText, font);
            int morePadding = 0;
            int moreRightOffset = 1;

            Size moreRectSize = new Size(Convert.ToInt32(moreTextSize.Width) + morePadding * 2, Convert.ToInt32(moreTextSize.Height) + morePadding * 2);
            Point moreRectLocation = new Point(_controlRect.Right - moreRectSize.Width - moreRightOffset, _lineRect.Bottom);
            Rectangle moreRect = new Rectangle(moreRectLocation, moreRectSize);

            // It's necessary to double-buffer the text drawing, because GDI
            // text drawing doesn't work well in these behavior controls.
            using (Bitmap bitmap = new Bitmap(moreRect.Width, moreRect.Height))
            {
                using (Graphics moreG = Graphics.FromImage(bitmap))
                {
                    using (SolidBrush b = new SolidBrush(backgroundColor))
                        moreG.FillRectangle(b, 0, 0, moreRect.Width, moreRect.Height);
                    new BidiGraphics(moreG, moreRect.Size).DrawText(_moreText, font, new Rectangle(Point.Empty, moreRect.Size), Color.White, backgroundColor, TextFormatFlags.Default);
                }

                g.DrawImage(false, bitmap, moreRect);
            }
        }
Esempio n. 30
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;

            // get item text and image
            string itemText = Items[e.Index].ToString();
            IComboItem comboItem = (IComboItem)Items[e.Index];
            Image itemImage = comboItem.Image;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;
            if (selected && Focused)
            {
                textColor = SystemColors.ControlText;
                backColor = Color.FromArgb(50, SystemColors.Highlight);
            }
            else
            {
                backColor = SystemColors.Window;
                textColor = SystemColors.ControlText;
            }
            Rectangle area = e.Bounds;
            //overlap issue in RTL builds in the selected box area ONLY
            if (area.X == 21)
            {
                area = ClientRectangle;
            }
            BidiGraphics g = new BidiGraphics(e.Graphics, area);

            // draw background (always paint white over it first)
            g.FillRectangle(Brushes.White, area);
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, area);

            // draw icon
            g.DrawImage(AllowMirroring, itemImage, area.Left + IMAGE_INSET, area.Top + area.Height / 2 - itemImage.Height / 2);

            // text format and drawing metrics
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter |
                   TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;
            int leftMargin = IMAGE_INSET + itemImage.Width + TEXT_INSET;

            // draw title line
            // post title
            int titleWidth = area.Right - leftMargin;
            Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height);
            g.DrawText(
                itemText,
                e.Font, titleRectangle, textColor, ellipsesStringFormat);

            // separator line if necessary
            if (!selected && DroppedDown)
            {
                using (Pen pen = new Pen(SystemColors.ControlLight))
                    g.DrawLine(pen, area.Left, area.Bottom - 1, area.Right, area.Bottom - 1);
            }

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }