コード例 #1
0
        /// <summary>
        /// Draw method
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            // Base painting
            base.OnPaint(e);
            Graphics g = e.Graphics;

            DIP.GetGraphics(g);

            // Handles control's source theme
            // Check if control has set own theme
            if (Owner.UsedTheme != null)
            {
                // Set custom theme as source theme
                _sourceTheme = Owner.UsedTheme;
            }
            else
            {
                // Control dont have its own theme
                // Try cast control's parent form to MForm
                try
                {
                    MForm form = (MForm)FindForm();
                    _sourceTheme = form.UsedTheme;
                }
                catch
                {
                    // Control's parent form is not MForm type
                    // Set application wide theme
                    _sourceTheme = Minimal.UsedTheme;
                }
            }

            // Draw item background
            Color fill = (Owner.MenuItem == this) ? _sourceTheme.WINDOW_CAPTIONBAR.Normal.ToColor() : MColor.Mix(Color.FromArgb(_hoverAlpha, MColor.Lighten(230, _tint, _sourceTheme.WINDOW_CAPTIONBAR.Normal.ToColor())), _sourceTheme.WINDOW_CAPTIONBAR.Normal.ToColor());

            g.FillRectangle(new SolidBrush(fill), new Rectangle(0, 0, Width, Height));

            if (FullColored)
            {
                g.FillRectangle(new SolidBrush(MColor.Mix(Color.FromArgb(_hoverAlpha, MColor.AddRGB((_sourceTheme.DARK_BASED) ? +(_hoverAlpha / 15) : -(_hoverAlpha / 15), _tint)), _tint)), new Rectangle(0, 0, Owner.MenuItem.Height, Owner.MenuItem.Height));
            }

            // Click effect
            DrawClick(e);

            // Icon mode
            if (_icon != null && !_fullColored)
            {
                if (_sourceTheme.DARK_BASED)
                {
                    _icon.DarkBased = true;
                }
                else
                {
                    _icon.DarkBased = false;
                }
            }

            // Draw Icon
            if (_icon != null)
            {
                g.InterpolationMode = InterpolationMode.NearestNeighbor;

                if (Owner.SelectedItem == this)
                {
                    Image img = MColor.SetImageColor(_icon.Icon, _tint);
                    g.DrawImage(MColor.SetImageOpacity(img, 1f), 16, 16, 32, 32);
                }
                else
                {
                    g.DrawImage(MColor.SetImageOpacity(_icon.Icon, 1f), 16, 16, 32, 32);
                }
            }
            else
            {
                // Icon rect
                g.DrawRectangle(new Pen(_sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()), new Rectangle(20, 20, 20, 20));
            }

            // Draw text
            SolidBrush brush = (Owner.SelectedItem == this) ? new SolidBrush(_tint) : (_fullColored) ? new SolidBrush(ForeColor) : new SolidBrush(_sourceTheme.CONTROL_FOREGROUND.Normal.ToColor());

            g.DrawString(Text, Font, brush, new Rectangle(65, (Height / 2) - (Font.Height / 2), Width, Height));
        }