카테고리 없음2009. 3. 20. 14:56

6

//int textwidth = (int)(g.MeasureString(text, SystemInformation.MenuFont).Width);
            int textwidth = (int)(g.MeasureString(text, new Font("Tahoma", 9)).Width);
            int x = toplevel ? bounds.Left + (bounds.Width - textwidth) / 2 : bounds.Left + iconSize + 10;
            int topGap = 4;
            if (toplevel) topGap = 2;
            int y = bounds.Top + topGap;
            Brush brush = null;

            if (!enabled)
                brush = new SolidBrush(Color.FromArgb(120, SystemColors.MenuText));
            else if (highContrast)
                brush = new SolidBrush(Color.FromArgb(255, SystemColors.MenuText));
            else
                brush = new SolidBrush(Color.Black);

            if (whiteHighContrast && ((state & DrawItemState.HotLight) > 0
                || ((state & DrawItemState.Selected) > 0 && !toplevel)))
                brush = new SolidBrush(Color.FromArgb(255, Color.White));

            if (toplevel) text = textTopMenu;
            //g.DrawString(text, SystemInformation.MenuFont, brush, x, y, stringformat);
            g.DrawString(text, new Font("Tahoma", 9), brush, x, y, stringformat);

            // don't draw the shortcut for top level menus
            // in case there was actually one
            if (!toplevel)
            {
                // draw shortcut right aligned
                stringformat.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                //g.DrawString(shortcut, SystemInformation.MenuFont, brush, bounds.Width - 10 , bounds.Top + topGap, stringformat);
                g.DrawString(shortcut, new Font("Tahoma", 9), brush, bounds.Width - 10, bounds.Top + topGap, stringformat);
            }
        }
    }
    public class ColorGroup
    {
        public ColorGroup(Color bgcolor, Color stripecolor, Color selectioncolor, Color bordercolor)
        {
            this.bgcolor = bgcolor;
            this.stripecolor = stripecolor;
            this.selectioncolor = Color.FromArgb(233, 155, 23);
            this.bordercolor = bordercolor;
        }

        Color bgcolor;
        Color stripecolor;
        Color selectioncolor;
        Color bordercolor;

        public Color bgColor
        {
            get { return bgcolor; }
        }

        public Color stripeColor
        {
            get { return stripecolor; }
        }

        public Color selectionColor
        {
            get { return selectioncolor; }
        }

        public Color borderColor
        {
            get { return bordercolor; }
        }

        public static ColorGroup GetColorGroup()
        {
            ColorGroup colorGroup = null;
            Color backgroundColor = CalculateColor(SystemColors.Window,
                SystemColors.Control, 220);
            Color selectionColor = CalculateColor(SystemColors.Highlight,
                SystemColors.Window, 70);
            Color stripColor = CalculateColor(SystemColors.Control,
                backgroundColor, 195);
            colorGroup = new ColorGroup(backgroundColor, stripColor, selectionColor,
                Color.FromArgb(255, SystemColors.Highlight));

            return colorGroup;
        }

        private static Color CalculateColor(Color front, Color back, int alpha)
        {
            // Use alpha blending to brigthen the colors but don't use it
            // directly. Instead derive an opaque color that we can use.
            // -- if we use a color with alpha blending directly we won't be able
            // to paint over whatever color was in the background and there
            // would be shadows of that color showing through
            Color frontColor = Color.FromArgb(255, front);
            Color backColor = Color.FromArgb(255, back);

            float frontRed = frontColor.R;
            float frontGreen = frontColor.G;
            float frontBlue = frontColor.B;
            float backRed = backColor.R;
            float backGreen = backColor.G;
            float backBlue = backColor.B;

            float fRed = frontRed * alpha / 255 + backRed * ((float)(255 - alpha) / 255);
            byte newRed = (byte)fRed;
            float fGreen = frontGreen * alpha / 255 + backGreen * ((float)(255 - alpha) / 255);
            byte newGreen = (byte)fGreen;
            float fBlue = frontBlue * alpha / 255 + backBlue * ((float)(255 - alpha) / 255);
            byte newBlue = (byte)fBlue;

            return Color.FromArgb(255, newRed, newGreen, newBlue);
        }
    }
}


Posted by penguindori