private void UpdateMainMenuBrush()
        {
            // screen states where there is no menu yet
            if (Menu == null)
                return;

            if (WindowState == FormWindowState.Minimized)
                return;

            // alias colorized resources
            ColorizedResources cres = ColorizedResources.Instance;

            // dispose any existing brush and/or bitmaps
            if (_hMainMenuBrush != IntPtr.Zero)
                DisposeGDIObject(ref _hMainMenuBrush);
            if (_hMainMenuBitmap != IntPtr.Zero)
                DisposeGDIObject(ref _hMainMenuBitmap);
            if (_hMainMenuBrushBitmap != IntPtr.Zero)
                DisposeGDIObject(ref _hMainMenuBrushBitmap);
            if (_mainMenuBitmap != null)
            {
                Bitmap tmp = _mainMenuBitmap;
                _mainMenuBitmap = null;
                tmp.Dispose();
            }

            // create a brush which contains the menu background
            _mainMenuBitmap = new Bitmap(Width, -RelativeWindowBounds.Y);
            _hMainMenuBitmap = _mainMenuBitmap.GetHbitmap();
            using (Graphics g = Graphics.FromImage(_mainMenuBitmap))
            {
                Rectangle bounds = MenuBounds;
                Debug.WriteLine("MenuBounds: " + bounds);
                if (cres.CustomMainMenuPainting)
                {
                    // paint custom menu background
                    CustomPaintMenuBackground(g, bounds);
                }
                else
                {
                    using (Brush brush = new SolidBrush(SystemMainMenuColor))
                        g.FillRectangle(brush, bounds);
                }
            }

            _hMainMenuBrushBitmap = _mainMenuBitmap.GetHbitmap();
            _hMainMenuBrush = Gdi32.CreatePatternBrush(_hMainMenuBrushBitmap);

            // set the brush
            MENUINFO mi = new MENUINFO();
            mi.cbSize = Marshal.SizeOf(typeof(MENUINFO));
            mi.fMask = MIM.BACKGROUND;
            mi.hbrBack = _hMainMenuBrush;
            User32.SetMenuInfo(Menu.Handle, ref mi);
            User32.DrawMenuBar(Handle);
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            ColorizedResources colRes = ColorizedResources.Instance;
            Color blockColor          = colRes.SidebarHeaderBackgroundColor;

            using (Brush b = new SolidBrush(colRes.SidebarGradientBottomColor))
                e.Graphics.FillRectangle(b, ClientRectangle);
            using (Brush b = new SolidBrush(blockColor))
                e.Graphics.FillRectangle(b, 0, 0, ClientSize.Width, BLOCK_HEIGHT);
        }
        private void CustomPaintMenuBackground(Graphics g, Rectangle menuBounds)
        {
            ColorizedResources cres = ColorizedResources.Instance;

            // Fill in the background--important for narrow window sizes when the main menu items are stacked
            using (Brush brush = new SolidBrush(cres.MainMenuGradientTopColor))
                g.FillRectangle(brush, new Rectangle(0, 0, Width, -RelativeWindowBounds.Y));

            // Fill in the gradient
            using (Brush brush = new LinearGradientBrush(menuBounds, cres.MainMenuGradientTopColor, cres.MainMenuGradientBottomColor, LinearGradientMode.Vertical))
                g.FillRectangle(brush, menuBounds);
        }
Example #4
0
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);

            ColorizedResources colRes = ColorizedResources.Instance;

            using (Brush b = new SolidBrush(colRes.SidebarGradientBottomColor))
                pevent.Graphics.FillRectangle(b, ClientRectangle);
            Rectangle gradientRect = new Rectangle(0, 0, ClientSize.Width, 65);

            using (Brush b = new LinearGradientBrush(gradientRect, colRes.SidebarGradientTopColor, colRes.SidebarGradientBottomColor, LinearGradientMode.Vertical))
                pevent.Graphics.FillRectangle(b, gradientRect);
        }
Example #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientSize, false);

            ColorizedResources colRes = ColorizedResources.Instance;

            // draw the outer border
            using (Pen p = new Pen(colRes.BorderDarkColor, 1))
                g.DrawRectangle(p, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1));

            // draw the caption
            using (Font f = Res.GetFont(FontSize.Large, FontStyle.Bold))
                g.DrawText(Text, f, new Rectangle(19, 8, ClientSize.Width - 1, ClientSize.Height - 1), SystemColors.WindowText, TextFormatFlags.NoPrefix);

            GdiTextHelper.DrawString(this, labelPublishingTo.Font, _progressMessage, labelPublishingTo.Bounds, false, GdiTextDrawMode.EndEllipsis);
        }
Example #6
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();
        }