コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

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

            //get the rectanlge representing the text in the label
            Rectangle textRectangle = GetMeasuredTextRectangle();

            //paint the line bevels to the left and right of the text
            if (textRectangle.Left != 0)
            {
                Rectangle leftRectangle = new Rectangle(0,
                    (Utility.Center(bevel.Height, textRectangle.Height) + textRectangle.Top + BEVEL_TEXT_MIDDLE_OFFSET),
                    textRectangle.X,
                    bevel.Height
                    );
                GraphicsHelper.TileFillScaledImageHorizontally(g, bevel, leftRectangle);
            }
            if (textRectangle.Right != ClientRectangle.Right)
            {
                int startX = textRectangle.Right + 3;
                Rectangle rightRectangle = new Rectangle(startX,
                    Utility.Center(bevel.Height, textRectangle.Height) + textRectangle.Top + BEVEL_TEXT_MIDDLE_OFFSET,
                    ClientRectangle.Width - startX,
                    bevel.Height
                    );
                GraphicsHelper.TileFillScaledImageHorizontally(g, bevel, rightRectangle);
            }
        }
コード例 #2
0
        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);
            }

        }
コード例 #3
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);
            g.DrawText(Res.Get(StringId.MapSeeInBirdseye), Font,
                       new Rectangle(ScaleX(TEXT_INSET), 0, Width - ScaleX(TEXT_INSET + 5), Height), Color.Black, TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak);

        }
コード例 #4
0
        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));
        }
コード例 #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);
            using (Brush b = new SolidBrush(ColorizedResources.Instance.BorderDarkColor))
                g.FillRectangle(b, ClientRectangle);

            TextFormatFlags tf = TextFormatFlags.VerticalCenter;
            int width = g.MeasureText(Text, Font).Width;
            g.DrawText(Text, Font, new Rectangle(20, -1, width, ClientSize.Height), _uiTheme.TextColor, tf);
        }
コード例 #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            StringFormat format = new StringFormat();
            format.LineAlignment = StringAlignment.Center;
            Rectangle rectangle = ClientRectangle;

            // draw text
            g.DrawText(HeaderText, _font, rectangle, ColorizedResources.Instance.SidebarHeaderTextColor, TextFormatFlags.VerticalCenter);
        }
コード例 #7
0
        private static void DrawSystemButtonFace(BidiGraphics graphics, bool DropDownContextMenuUserInterface, bool contextMenuShowing, Rectangle VirtualClientRectangle, bool isLargeButton, ButtonSettings settings)
        {
            // calculate bitmaps
            Bitmap hoverButtonFace = isLargeButton ? buttonFaceBitmapLarge : buttonFaceBitmap;
            Bitmap pressedButtonFace = isLargeButton ? buttonFacePushedBitmapLarge : buttonFacePushedBitmap;

            // draw button face
            DrawSystemButtonFace(graphics,
                                 DropDownContextMenuUserInterface,
                                 VirtualClientRectangle,
                                 hoverButtonFace,
                                 contextMenuShowing ? pressedButtonFace : hoverButtonFace,
                                 isLargeButton,
                                 settings);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            if (IsHovered || (SystemInformation.HighContrast && Focused))
            {
                BorderPaint borderPaint = new BorderPaint(ResourceHelper.LoadAssemblyResourceBitmap("Images.ChoiceOptionHover.png"), true, BorderPaintMode.StretchToFill | BorderPaintMode.PaintMiddleCenter, 3, 4, 3, 71);
                borderPaint.DrawBorder(e.Graphics, ClientRectangle);
            }
            else if (Focused)
            {
                BorderPaint borderPaint = new BorderPaint(ResourceHelper.LoadAssemblyResourceBitmap("Images.ChoiceOptionFocus.png"), true, BorderPaintMode.StretchToFill | BorderPaintMode.PaintMiddleCenter, 3, 4, 3, 71);
                borderPaint.DrawBorder(e.Graphics, ClientRectangle);
            }

            // Draw everything else
            Render(g, ClientRectangle.Width, ClientRectangle.Height);
        }
コード例 #10
0
        private static void DrawSystemButtonFace(BidiGraphics graphics, bool DropDownContextMenuUserInterface, Rectangle clientRectangle, Image buttonBitmap, Image contextMenuButtonBitmap, bool isLargeButton, ButtonSettings settings)
        {
            // get rectangles
            Rectangle leftRectangle = isLargeButton ? buttonFaceLeftRectangleLarge : buttonFaceLeftRectangle;
            Rectangle centerRectangle = isLargeButton ? buttonFaceCenterRectangleLarge : buttonFaceCenterRectangle;
            Rectangle rightRectangle = isLargeButton ? buttonFaceRightRectangleLarge : buttonFaceRightRectangle;

            // determine height
            int height = isLargeButton ? LARGE_BUTTON_TOTAL_SIZE : clientRectangle.Height;

            //	Compute the button face rectangle.
            Rectangle buttonRectangle = new Rectangle(clientRectangle.X,
                clientRectangle.Y,
                clientRectangle.Width,
                height);

            if (DropDownContextMenuUserInterface)
            {
                //	Compute the drop-down rectangle.
                Rectangle dropDownRectangle = new Rectangle(clientRectangle.Right - settings.DROP_DOWN_BUTTON_WIDTH,
                    clientRectangle.Y,
                    settings.DROP_DOWN_BUTTON_WIDTH,
                    height);
                GraphicsHelper.DrawLeftCenterRightImageBorder(graphics,
                    dropDownRectangle,
                    contextMenuButtonBitmap,
                    leftRectangle,
                    centerRectangle,
                    rightRectangle);

                buttonRectangle.Width -= dropDownRectangle.Width - 1;
            }

            //	Draw the border.
            GraphicsHelper.DrawLeftCenterRightImageBorder(graphics,
                buttonRectangle,
                buttonBitmap,
                leftRectangle,
                centerRectangle,
                rightRectangle);
        }
コード例 #11
0
 public void Paint(BidiGraphics g)
 {
     if ( !_havePostsToDisplay )
     {
         string noPosts = String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.NoThings), _title ) ;
         Size size = g.MeasureText(noPosts, _font);
         g.DrawText(noPosts, _font,
             new Rectangle(Bounds.Location.X + POSTLIST_INDENT, Bounds.Location.Y + LINK_TEXT_PADDING, size.Width, size.Height),
             ColorizedResources.Instance.SidebarDisabledTextColor);
     }
 }
コード例 #12
0
        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 );
                }

            }
        }
コード例 #13
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;

            // get video we are rendering
            IVideo video = Items[e.Index] as IVideo;

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

            // calculate colors
            Color textColor;
            if (selected)
            {
                if (Focused)
                {
                    textColor = SystemColors.HighlightText;
                }
                else
                {
                    textColor = SystemColors.ControlText;
                }
            }
            else
            {
                textColor = SystemColors.ControlText;
            }
            Color previewColor = Color.FromArgb(200, textColor);

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

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

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

            // draw the thumbnail image
            Rectangle thumbnailRect = new Rectangle(e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(VERTICAL_INSET), THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
            VideoThumbnail thumbnail = _thumbnailManager.GetThumbnail(video);
            thumbnail.Draw(g, e.Font, thumbnailRect);

            // calculate standard text drawing metrics
            int leftMargin = ScaleX(HORIZONTAL_INSET) + THUMBNAIL_IMAGE_WIDTH + ScaleX(HORIZONTAL_INSET);
            int topMargin = e.Bounds.Top + ScaleY(VERTICAL_INSET);
            int fontHeight = g.MeasureText(video.Title, e.Font).Height;

            // draw title and duration
            int titleWidth;
            Rectangle durationRectangle;
            using (Font hyperlinkFont = new Font(e.Font, FontStyle.Underline))
            {
                titleWidth = e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - leftMargin;
                Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight);

                string title = video.Title ?? "";

                g.DrawText(title,
                    hyperlinkFont,
                    titleRectangle, selected ? textColor : SystemColors.HotTrack, ellipsesStringFormat);
            }

            using (Font durationFont = new Font(e.Font, FontStyle.Regular)) // was bold
            {
                durationRectangle = new Rectangle(leftMargin, topMargin + fontHeight + 3, titleWidth, fontHeight);

                string duration = String.Format(CultureInfo.InvariantCulture, "{0:00}:{1:00}", video.LengthSeconds / 60, video.LengthSeconds % 60);

                g.DrawText(
                    duration,
                    durationFont,
                    durationRectangle, textColor, ellipsesStringFormat);
            }

            // draw description

            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                leftMargin,
                durationRectangle.Bottom + ScaleY(VERTICAL_INSET),
                e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET),
                e.Bounds.Bottom - ScaleY(VERTICAL_INSET) - durationRectangle.Bottom - ScaleY(VERTICAL_INSET));

            // draw description
            g.DrawText(
                video.Description,
                e.Font, layoutRectangle, previewColor, ellipsesStringFormat);

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

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
コード例 #14
0
        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();
        }
コード例 #15
0
 public void Paint(BidiGraphics g)
 {
     Rectangle rectangle = CaptionBounds;
     g.DrawText(Caption, _font, rectangle, SystemColors.ControlText, TextFormatFlags.VerticalCenter);
 }
コード例 #16
0
 public void Paint(BidiGraphics g)
 {
     ColorizedResources colRes = ColorizedResources.Instance;
     g.DrawText(Caption, _captionFont, CaptionBounds, colRes.SidebarHeaderTextColor);
 }
コード例 #17
0
        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);
                }

            }
        }
コード例 #18
0
        public void Layout(Point startLocation)
        {
            InitFont();

            using ( Graphics g = Parent.CreateGraphics() )
            {
                // deterine room occcupied by icon
                const int ICON_PADDING = 2 ;
                int iconWidth = 0 ;
                if ( Image != null )
                    iconWidth = Image.Width + ICON_PADDING ;
                else if ( Icon != null )
                    iconWidth = Icon.Width + ICON_PADDING ;

                // compute widths
                int width = Parent.Width - (2*startLocation.X) - 1 ;
                int textWidth = width - iconWidth ;

                // compute height
                BidiGraphics bg = new BidiGraphics(g, Size.Empty);
                Size captionSize = bg.MeasureText(Caption, _captionFont, new Size(textWidth, 0), 0);
                int textHeight = Convert.ToInt32(Math.Min(captionSize.Height, _captionFont.GetHeight() * 3)) ;

                Point captionLocation = new Point(startLocation.X + iconWidth, startLocation.Y+1) ;

                CaptionBounds = new Rectangle(captionLocation, new Size(textWidth, textHeight));

                Bounds = new Rectangle(startLocation, new Size(width, CaptionBounds.Height + (SectionHeader.SECTION_CAPTION_TOP_INSET+SectionHeader.SECTION_CAPTION_BOTTOM_INSET)));

            }
        }
コード例 #19
0
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                // alias graphics object
                BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle) ;

                _openPanelHeader.Paint(g);
                _openPanelBody.Paint(g);

                _draftsSectionHeader.Paint(g);
                _draftsPostList.Paint(g);
                if (ShouldShowMoreDrafts)
                    _openDraftCommand.Paint(g);

                _recentPostsSectionHeader.Paint(g);
                _recentPostList.Paint(g);
                if (ShouldShowMoreRecentPosts)
                    _openPostCommand.Paint(g);

                _insertPanelHeader.Paint(g);
                _insertPanelBody.Paint(g);

                _insertLinkCommand.Paint(g);
                _insertPictureCommand.Paint(g);
                if (_insertPhotoAlbumCommand != null)
                    _insertPhotoAlbumCommand.Paint(g);
                if (_insertWebImage != null)
                    _insertWebImage.Paint(g);
                _insertTableCommand.Paint(g);
                _contentInsertCommands.Paint(g);

            }
            catch(Exception ex)
            {
                Trace.Fail("Unexpected exception: " + ex.ToString()) ;
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        public void Paint(BidiGraphics g)
        {
            foreach ( LinkCommand linkCommand in _contentSourceCommands )
                linkCommand.Paint(g);

            if (MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.WLGallery))
            {
                int y = _addPluginCommand.Bounds.Y - ADD_PLUGIN_PAD ;
                using ( Pen pen = PanelBody.CreateBorderPen() )
                    g.DrawLine(pen, _addPluginCommand.Bounds.X, y, _parent.Right - _addPluginCommand.Bounds.X, y);

                _addPluginCommand.Paint(g);
            }
        }
コード例 #22
0
        /// <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);
            }
        }
コード例 #23
0
        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 );
        }
コード例 #24
0
        /// <summary>
        /// Draws a top-level menu item.
        /// </summary>
        /// <param name="drawItemState">A DrawItemEventArgs that contains the event data.</param>
        private void DrawMainMenuItem(DrawItemEventArgs ea)
        {
            // record state
            DrawItemState drawItemState = ea.State;

            //	Create graphics context on the offscreen bitmap and set the bounds for painting.
            //Graphics graphics = Graphics.FromImage(offscreenBitmap);
            Graphics graphics = ea.Graphics;

            BidiGraphics g = new BidiGraphics(graphics, new Size(GetMainMenu().GetForm().Width, 0));

            //Rectangle bounds = new Rectangle(0, 0, offscreenBitmap.Width, offscreenBitmap.Height);
            Rectangle bounds = ea.Bounds;

            // get reference to colorized resources
            ColorizedResources cres = ColorizedResources.Instance;

            //	Fill the menu item with the correct color
            Form containingForm = GetMainMenu().GetForm();
            if ((containingForm is IMainMenuBackgroundPainter))
            {
                (containingForm as IMainMenuBackgroundPainter).PaintBackground(g.Graphics, g.TranslateRectangle(ea.Bounds));
            }
            else
            {
                g.FillRectangle(SystemBrushes.Control, bounds);
            }

            //	Draw the hotlight or selection rectangle.
            if ((drawItemState & DrawItemState.HotLight) != 0 || (drawItemState & DrawItemState.Selected) != 0)
            {
                //	Cheat some for the first top-level menu item.  Provide a bit of "air" at the
                //	left of the "HotLight" rectangle so it doesn't run into the frame.
                int xOffset = (Index == 0) ? 1 : 0;

                //	Calculate the hotlight rectangle.
                Rectangle hotlightRectangle = new Rectangle(bounds.X + xOffset,
                                                                bounds.Y + 1,
                                                                bounds.Width - xOffset - 1,
                                                                bounds.Height - 1);
                DrawHotlight(g, cres.MainMenuHighlightColor, hotlightRectangle, !cres.CustomMainMenuPainting);
            }

            //	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"
            //	after all), but this is just how it works.
            Rectangle textAreaRectangle = new Rectangle(bounds.X,
                                                            bounds.Y + 1,
                                                            bounds.Width,
                                                            bounds.Height);

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

            //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, MenuText(), ref stringFormat, ref textAreaRectangle);

            //	Draw the shortcut and the menu text.
            TextRenderer.DrawText(g.Graphics, MenuText(), menuFont, textAreaRectangle, cres.MainMenuTextColor, textFormat);

            //	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();
        }
コード例 #25
0
 public void Layout(Point startLocation)
 {
     InitFont() ;
     using ( Graphics g = Parent.CreateGraphics() )
     {
         BidiGraphics bg = new BidiGraphics(g, Size.Empty);
         Size stringSize = bg.MeasureText(Caption, _captionFont);
         int textHeight = stringSize.Height;
         Point captionLocation = startLocation ;
         captionLocation.Offset(PANEL_CAPTION_LEFT_INSET, PANEL_CAPTION_TOP_INSET);
         CaptionBounds = new Rectangle(captionLocation, stringSize);
         Bounds = new Rectangle(startLocation, new Size(Parent.Width-startLocation.X*2-1, textHeight + (PANEL_CAPTION_TOP_INSET+PANEL_CAPTION_BOTTOM_INSET))) ;
     }
 }
コード例 #26
0
        private static void DrawHotlight(BidiGraphics graphics, Color highlightColor, Rectangle hotlightRectangle, bool drawBackground)
        {
            //	Fill the menu item with the system-defined menu color so the highlight color
            //	looks right.
            if (drawBackground)
                graphics.FillRectangle(SystemBrushes.Menu, hotlightRectangle);

            //	Draw the selection indicator using a 25% opaque version of the highlight color.
            using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(64, highlightColor)))
                graphics.FillRectangle(solidBrush, hotlightRectangle);

            //	Draw a rectangle around the selection indicator to frame it in better using a
            //	50% opaque version of the highlight color (this combines with the selection
            //	indicator to be 75% opaque).
            using (Pen pen = new Pen(Color.FromArgb(128, highlightColor)))
                graphics.DrawRectangle(
                    pen, new Rectangle(
                                        hotlightRectangle.X,
                                        hotlightRectangle.Y,
                                        hotlightRectangle.Width - 1,
                                        hotlightRectangle.Height - 1));
        }
コード例 #27
0
        public void Paint(BidiGraphics g)
        {
            ColorizedResources colRes = ColorizedResources.Instance;

            if(!ColorizedResources.UseSystemColors)
            {
                using (Brush b = new SolidBrush(Color.FromArgb(64, Color.White)))
                    g.FillRectangle(b, Bounds );

                using (Pen p = CreateBorderPen())
                {
                    g.DrawLine(p, Bounds.Left, Bounds.Top, Bounds.Left, Bounds.Bottom - 1); // left
                    g.DrawLine(p, Bounds.Right, Bounds.Top, Bounds.Right, Bounds.Bottom - 1); // left
                    g.DrawLine(p, Bounds.Left + 1, Bounds.Bottom, Bounds.Right - 1, Bounds.Bottom);
                }
            }
        }
コード例 #28
0
        /// <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();
            }
        }
        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);
            }
        }
コード例 #30
0
        protected override void OnPaint(PaintEventArgs e)
        {

            base.OnPaint(e);
            BidiGraphics g = new BidiGraphics(e.Graphics, VirtualClientRectangle);

            Rectangle tabRectangle = VirtualClientRectangle;

            if (selected)
                ColorizedResources.Instance.ViewSwitchingTabSelected.DrawBorder(e.Graphics, tabRectangle);
            else
                ColorizedResources.Instance.ViewSwitchingTabUnselected.DrawBorder(e.Graphics, tabRectangle);

            if (ColorizedResources.UseSystemColors)
            {
                if (BorderColor.HasValue)
                {
                    using (Pen pen = new Pen(BorderColor.Value))
                    {
                        if (!selected)
                            g.DrawLine(pen, tabRectangle.Left, tabRectangle.Top, tabRectangle.Right,
                                       tabRectangle.Top);
                        g.DrawLine(pen, tabRectangle.Left, tabRectangle.Top, tabRectangle.Left,
                                   tabRectangle.Bottom);
                        g.DrawLine(pen, tabRectangle.Right - 1, tabRectangle.Top, tabRectangle.Right - 1,
                                   tabRectangle.Bottom);
                        g.DrawLine(pen, tabRectangle.Left, tabRectangle.Bottom - 1,
                                   tabRectangle.Right, tabRectangle.Bottom - 1);
                    }
                }
            }

            /*
            if (!selected && !SystemInformation.HighContrast)
            {

                using (Pen p = new Pen(borderColor, 1.0f))
                    g.DrawLine(p, 0, 0, VirtualWidth, 0);
                using (Pen p = new Pen(Color.FromArgb(192, borderColor), 1.0f))
                    g.DrawLine(p, 0, 1, VirtualWidth - 1, 1);
                using (Pen p = new Pen(Color.FromArgb(128, borderColor), 1.0f))
                    g.DrawLine(p, 0, 2, VirtualWidth - 2, 2);
                using (Pen p = new Pen(Color.FromArgb(64, borderColor), 1.0f))
                    g.DrawLine(p, 0, 3, VirtualWidth - 2, 3);
            }
             * */

            Rectangle textBounds = tabRectangle;
            if (!selected)
                textBounds.Y += (int)DisplayHelper.ScaleX(3);
            else
                textBounds.Y += (int)DisplayHelper.ScaleX(3);

            Color textColor = ColorizedResources.Instance.MainMenuTextColor;
            if (selected)
                textColor = Parent.ForeColor;

            g.DrawText(Text, selected ? ctx.Font : ctx.Font, textBounds, SystemInformation.HighContrast ? SystemColors.ControlText : textColor,
                       TextFormatFlags.Top | TextFormatFlags.HorizontalCenter | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping);
        }