ToKnownColor() публичный Метод

public ToKnownColor ( ) : KnownColor
Результат KnownColor
Пример #1
0
        public void SaveSettings(RichTextBox rtb)
        {
            try
            {
                PutSetting("BaseIEName", BaseIEName);
                PutSetting("PopupIEName", PopupIEName);
                PutSetting("TypingTime", TypingTime.ToString());
                PutSetting("FindPattern", FindPattern);
                PutSetting("WarnWhenUnsaved", WarnWhenUnsaved ? 1 : 0);
                PutSetting("HideDOSWindow", HideDOSWindow ? 1 : 0);
                PutSetting("CompilePath", CompilePath);
                PutSetting("DOMHighlightColor", DOMHighlightColor.ToKnownColor().ToString());
                PutSetting("CodeLanguage", System.Enum.GetName(typeof(CodeLanguages), CodeLanguage));
                PutSetting("ScriptFormatting", System.Enum.GetName(typeof(ScriptFormats), ScriptFormatting));
                PutSetting("FontName", rtb.Font.FontFamily.Name);
                PutSetting("FontSize", rtb.Font.Size.ToString());
                PutSetting("RunCount", ++RunCount);

                PutSetting("DefaultSaveTemplate", DefaultSaveTemplate);
                PutSetting("DefaultRunTemplate", DefaultRunTemplate);
                PutSetting("DefaultCompileTemplate", DefaultCompileTemplate);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error saving settings: {0}", ex.Message));
            }
        }
		public static void Serialize(SerializationWriter writer, Color color)
		{
			BitVector32 flags = new BitVector32();

			if (color.IsKnownColor)
				flags[ColorIsKnown] = true;
			else if (color.IsNamedColor)
				flags[ColorHasName] = true;
			else if (!color.IsEmpty)
			{
				flags[ColorHasValue] = true;
				flags[ColorHasRed] = color.R != 0;
				flags[ColorHasGreen] = color.G != 0;
				flags[ColorHasBlue] = color.B != 0;
				flags[ColorHasAlpha] = color.A != 0;
			}
			writer.WriteOptimized(flags);

			if (color.IsKnownColor)
				writer.WriteOptimized((int) color.ToKnownColor());
			else if (color.IsNamedColor)
				writer.WriteOptimized(color.Name);
			else if (!color.IsEmpty)
			{
				byte component;
				if ( (component = color.R) != 0) writer.Write(component);	
				if ( (component = color.G) != 0) writer.Write(component);	
				if ( (component = color.B) != 0) writer.Write(component);	
				if ( (component = color.A) != 0) writer.Write(component);	
			}
		}
Пример #3
0
        private String montaCelula(String texto, Boolean negrito, EnunAlinhamentos alinhamento, System.Drawing.Color cor)
        {
            String retorno = "<td align='" + alinhamento.ToString() + "'" +
                             "bgcolor='" + cor.ToKnownColor() + "'" + " >" +
                             ((negrito) ? "<B>" : "") + texto + ((negrito) ? "</B>" : "") + "</td>";

            return(retorno);
        }
Пример #4
0
        private String montaCelula(String texto, Boolean negrito, EnunAlinhamentos alinhamento, System.Drawing.Color cor, String tipo, String ID)
        {
            String retorno = "";

            retorno = "<td align='" + alinhamento.ToString() + "'" +
                      "bgcolor='" + cor.ToKnownColor() + "' >" +
                      "<" + tipo + " href='" + "' target='_blank'server' >" + texto + "</" + tipo + ">";
            return(retorno);
        }
Пример #5
0
        /// <include file='doc\ControlPaint.uex' path='docs/doc[@for="ControlPaint.HLSColor.HLSColor"]/*' />
        /// <devdoc>
        /// </devdoc>
        public HLSColor(Color color)
        {
            isSystemColors_Control = (color.ToKnownColor() == SystemColors.Control.ToKnownColor());
            int r = color.R;
            int g = color.G;
            int b = color.B;
            int max, min;        /* max and min RGB values */
            int sum, dif;
            int Rdelta, Gdelta, Bdelta;  /* intermediate value: % of spread from max */

            /* calculate lightness */
            max = Math.Max(Math.Max(r, g), b);
            min = Math.Min(Math.Min(r, g), b);
            sum = max + min;

            luminosity = (((sum * HLSMax) + RGBMax) / (2 * RGBMax));

            dif = max - min;
            if (dif == 0)
            {       /* r=g=b --> achromatic case */
                saturation = 0;                         /* saturation */
                hue = Undefined;                 /* hue */
            }
            else
            {                           /* chromatic case */
                /* saturation */
                if (luminosity <= (HLSMax / 2))
                    saturation = (int)(((dif * (int)HLSMax) + (sum / 2)) / sum);
                else
                    saturation = (int)((int)((dif * (int)HLSMax) + (int)((2 * RGBMax - sum) / 2))
                                        / (2 * RGBMax - sum));
                /* hue */
                Rdelta = (int)((((max - r) * (int)(HLSMax / 6)) + (dif / 2)) / dif);
                Gdelta = (int)((((max - g) * (int)(HLSMax / 6)) + (dif / 2)) / dif);
                Bdelta = (int)((((max - b) * (int)(HLSMax / 6)) + (dif / 2)) / dif);

                if ((int)r == max)
                    hue = Bdelta - Gdelta;
                else if ((int)g == max)
                    hue = (HLSMax / 3) + Rdelta - Bdelta;
                else /* B == cMax */
                    hue = ((2 * HLSMax) / 3) + Gdelta - Rdelta;

                if (hue < 0)
                    hue += HLSMax;
                if (hue > HLSMax)
                    hue -= HLSMax;
            }
        }
 public static Pen FromSystemColor(Color c)
 {
     if (!c.IsSystemColor)
     {
         throw new ArgumentException(System.Drawing.SR.GetString("ColorNotSystemColor", new object[] { c.ToString() }));
     }
     Pen[] penArray = (Pen[]) SafeNativeMethods.Gdip.ThreadData[SystemPensKey];
     if (penArray == null)
     {
         penArray = new Pen[0x21];
         SafeNativeMethods.Gdip.ThreadData[SystemPensKey] = penArray;
     }
     int index = (int) c.ToKnownColor();
     if (index > 0xa7)
     {
         index -= 0x8d;
     }
     index--;
     if (penArray[index] == null)
     {
         penArray[index] = new Pen(c, true);
     }
     return penArray[index];
 }
 public static Brush FromSystemColor(Color c)
 {
     if (!c.IsSystemColor)
     {
         throw new ArgumentException(System.Drawing.SR.GetString("ColorNotSystemColor", new object[] { c.ToString() }));
     }
     Brush[] brushArray = (Brush[]) SafeNativeMethods.Gdip.ThreadData[SystemBrushesKey];
     if (brushArray == null)
     {
         brushArray = new Brush[0x21];
         SafeNativeMethods.Gdip.ThreadData[SystemBrushesKey] = brushArray;
     }
     int index = (int) c.ToKnownColor();
     if (index > 0xa7)
     {
         index -= 0x8d;
     }
     index--;
     if (brushArray[index] == null)
     {
         brushArray[index] = new SolidBrush(c, true);
     }
     return brushArray[index];
 }
Пример #8
0
        /// <summary>
        /// Write date to container with style.
        /// </summary>
        /// <param name="writer">HtmlTextWriter.</param>
        /// <param name="dwt">Date.</param>
        /// <param name="Container">HtmlContainer.</param>
        /// <param name="fWriteTime">Write date(false) or time(true).</param>
        /// <param name="UserID">ID of user.</param>
        private void WriteDataTime(HtmlTextWriter writer,
            DayWorkTime dwt,
            String Container,
            bool fWriteTime,
            int? UserID)
        {
            CalendarItem calItem = new CalendarItem(dwt);
            String strValue = fWriteTime
                                  ? DateTimePresenter.GetTime(dwt.WorkTime)
                                  : dwt.Date.ToString("dd/MM");

            Color cellColor = new Color();
               if (UserID != null
                && dwt.WorkTime == TimeSpan.Zero
                && !calItem.IsWeekend)
            {
                WorkEvent workEvent = WorkEvent.GetCurrentEventOfDate((int) UserID, dwt.Date);

                if (workEvent != null)
                    switch (workEvent.EventType)
                    {
                        case WorkEventType.BusinessTrip:
                            strValue = "Trip";
                            cellColor = Color.LightSlateGray;
                            break;

                        case WorkEventType.Ill:
                            strValue = "Ill";
                            cellColor = Color.LightPink;
                            break;

                        case WorkEventType.TrustIll:
                            strValue = "Trust Ill";
                            cellColor = Color.LightPink;
                            break;

                        case WorkEventType.Vacation:
                            strValue = "Vacation";
                            cellColor = Color.LightYellow;
                            break;
                    }
            }

            if (calItem.IsWeekend)
                writer.WriteLine("<{0} class='weekend'>{1}</{0}>",
                                 Container,
                                 strValue);
            else
                writer.WriteLine("<{0} style='background-color: {1};' align='center'>{2}</{0}>",
                                 Container,
                                 cellColor.ToKnownColor(),
                                 strValue);
        }
Пример #9
0
        /// <summary>
        /// Translates the specified <see cref='Color'/> to an Ole color.
        /// </summary>
        public static int ToOle(Color c)
        {
            // IMPORTANT: This signature is invoked directly by the runtime marshaler and cannot change without
            // also updating the runtime.

            // This method converts Color to an OLE_COLOR.
            // https://docs.microsoft.com/openspecs/office_file_formats/ms-oforms/4b8f4be0-3fff-4e42-9fc1-b9fd00251e8e

            if (c.IsKnownColor && c.IsSystemColor)
            {
                // Unfortunately KnownColor didn't keep the same ordering as the various GetSysColor()
                // COLOR_ * values, otherwise this could be greatly simplified.

                switch (c.ToKnownColor())
                {
                case KnownColor.ActiveBorder:
                    return(unchecked ((int)0x8000000A));

                case KnownColor.ActiveCaption:
                    return(unchecked ((int)0x80000002));

                case KnownColor.ActiveCaptionText:
                    return(unchecked ((int)0x80000009));

                case KnownColor.AppWorkspace:
                    return(unchecked ((int)0x8000000C));

                case KnownColor.ButtonFace:
                    return(unchecked ((int)0x8000000F));

                case KnownColor.ButtonHighlight:
                    return(unchecked ((int)0x80000014));

                case KnownColor.ButtonShadow:
                    return(unchecked ((int)0x80000010));

                case KnownColor.Control:
                    return(unchecked ((int)0x8000000F));

                case KnownColor.ControlDark:
                    return(unchecked ((int)0x80000010));

                case KnownColor.ControlDarkDark:
                    return(unchecked ((int)0x80000015));

                case KnownColor.ControlLight:
                    return(unchecked ((int)0x80000016));

                case KnownColor.ControlLightLight:
                    return(unchecked ((int)0x80000014));

                case KnownColor.ControlText:
                    return(unchecked ((int)0x80000012));

                case KnownColor.Desktop:
                    return(unchecked ((int)0x80000001));

                case KnownColor.GradientActiveCaption:
                    return(unchecked ((int)0x8000001B));

                case KnownColor.GradientInactiveCaption:
                    return(unchecked ((int)0x8000001C));

                case KnownColor.GrayText:
                    return(unchecked ((int)0x80000011));

                case KnownColor.Highlight:
                    return(unchecked ((int)0x8000000D));

                case KnownColor.HighlightText:
                    return(unchecked ((int)0x8000000E));

                case KnownColor.HotTrack:
                    return(unchecked ((int)0x8000001A));

                case KnownColor.InactiveBorder:
                    return(unchecked ((int)0x8000000B));

                case KnownColor.InactiveCaption:
                    return(unchecked ((int)0x80000003));

                case KnownColor.InactiveCaptionText:
                    return(unchecked ((int)0x80000013));

                case KnownColor.Info:
                    return(unchecked ((int)0x80000018));

                case KnownColor.InfoText:
                    return(unchecked ((int)0x80000017));

                case KnownColor.Menu:
                    return(unchecked ((int)0x80000004));

                case KnownColor.MenuBar:
                    return(unchecked ((int)0x8000001E));

                case KnownColor.MenuHighlight:
                    return(unchecked ((int)0x8000001D));

                case KnownColor.MenuText:
                    return(unchecked ((int)0x80000007));

                case KnownColor.ScrollBar:
                    return(unchecked ((int)0x80000000));

                case KnownColor.Window:
                    return(unchecked ((int)0x80000005));

                case KnownColor.WindowFrame:
                    return(unchecked ((int)0x80000006));

                case KnownColor.WindowText:
                    return(unchecked ((int)0x80000008));
                }
            }

            return(ToWin32(c));
        }
Пример #10
0
        //Color
        /// <summary>
        /// Stores the specified Color Object as a setting in the current SettingsKey.
        /// </summary>
        /// 
        /// <param name="settingName">
        /// The name of the setting to store.
        /// </param>
        /// 
        /// <param name="settingValue">
        /// The Color to store for this setting.
        /// </param>
        /// 
        /// <exception cref="UnauthorizedAccessException">
        /// This current SettingsKey is the root SettingsKey or is read-only.
        /// </exception>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The specified 'settingName' 
        /// is a null reference or an empty string or the specified
        /// 'settingValue' is null.
        /// </exception>
        /// 
        /// <remarks>
        /// To retrieve a stored Color from the settings file use the <see cref="GetColor"/> method.
        /// <para>
        /// Since many settings can be stored in each SettingsKey, 
        /// the 'settingName' parameter specifies the particular setting you wish to manipulate. 
        /// </para>
        /// 
        /// <para>
        /// The key that is opened with the setting being set must have been 
        /// opened with write access, and not be a read-only key. 
        /// Once you have been granted write-access to a key, you can change 
        /// the data associated with any of the settings in that key.
        /// </para>
        /// 
        /// <para>
        /// The parameter 'settingName' is  case-sensitive.
        /// </para>
        /// 
        /// <para>
        /// If the specified setting name does not exist in the key, 
        /// it will be created, and the sepecified settingValue is stored.
        /// </para>
        /// </remarks>
        public void StoreColor(string settingName, Color settingValue)
        {
            //encode name to a valid XML Name
            settingName = XmlConvert.EncodeName(settingName);

            #region conditions

            // is the settingValue parameter null
            if (settingValue.IsEmpty)
            {
                this.throwParameterNullException("setting");
            }

            #endregion

            if (settingValue.IsKnownColor)
            {
                StringBuilder str = new StringBuilder(settingValue.ToKnownColor().ToString());
                str.Insert(0,RES_KnownColorStartString);
                str.Append(RES_ColorEndChar);
                StoreSetting(settingName,str.ToString());
            }
            else
            {
                StringBuilder str = new StringBuilder(settingValue.ToArgb().ToString());

                str.Insert(0,RES_UnKnownColorStartString);
                str.Append(RES_ColorEndChar);

                StoreSetting(settingName,str.ToString());
            }
        }
Пример #11
0
        private string GetHtmlColor(Color color)
        {
            if (color.IsEmpty == true)
            {
                return string.Empty;
            }

            if (color.IsNamedColor == true)
            {
                return color.ToKnownColor().ToString();
            }

            if (color.IsSystemColor == true)
            {
                return color.ToString();
            }

            return "#" + color.ToArgb().ToString("x").Substring(2);
        }
Пример #12
0
 public static KnownColor ToKnownColor(Color c)
 {
     return(c.ToKnownColor());
 }
        /// <include file='doc\ColorTranslator.uex' path='docs/doc[@for="ColorTranslator.ToHtml"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Translates the specified <see cref='System.Drawing.Color'/> to an Html string color representation.
        ///    </para>
        /// </devdoc>
        public static string ToHtml(Color c) {
            string colorString = String.Empty;

            if (c.IsEmpty)
                return colorString;

            if (c.IsSystemColor) {
                switch (c.ToKnownColor()) {
                    case KnownColor.ActiveBorder: colorString = "activeborder"; break;
                    case KnownColor.GradientActiveCaption:
                    case KnownColor.ActiveCaption: colorString = "activecaption"; break;
                    case KnownColor.AppWorkspace: colorString = "appworkspace"; break;
                    case KnownColor.Desktop: colorString = "background"; break;
                    case KnownColor.Control: colorString = "buttonface"; break;
                    case KnownColor.ControlLight: colorString = "buttonface"; break;
                    case KnownColor.ControlDark: colorString = "buttonshadow"; break;
                    case KnownColor.ControlText: colorString = "buttontext"; break;
                    case KnownColor.ActiveCaptionText: colorString = "captiontext"; break;
                    case KnownColor.GrayText: colorString = "graytext"; break;
                    case KnownColor.HotTrack:
                    case KnownColor.Highlight: colorString = "highlight"; break;
                    case KnownColor.MenuHighlight:
                    case KnownColor.HighlightText: colorString = "highlighttext"; break;
                    case KnownColor.InactiveBorder: colorString = "inactiveborder"; break;
                    case KnownColor.GradientInactiveCaption:
                    case KnownColor.InactiveCaption: colorString = "inactivecaption"; break;
                    case KnownColor.InactiveCaptionText: colorString = "inactivecaptiontext"; break;
                    case KnownColor.Info: colorString = "infobackground"; break;
                    case KnownColor.InfoText: colorString = "infotext"; break;
                    case KnownColor.MenuBar:
                    case KnownColor.Menu: colorString = "menu"; break;
                    case KnownColor.MenuText: colorString = "menutext"; break;
                    case KnownColor.ScrollBar: colorString = "scrollbar"; break;
                    case KnownColor.ControlDarkDark: colorString = "threeddarkshadow"; break;
                    case KnownColor.ControlLightLight: colorString = "buttonhighlight"; break;
                    case KnownColor.Window: colorString = "window"; break;
                    case KnownColor.WindowFrame: colorString = "windowframe"; break;
                    case KnownColor.WindowText: colorString = "windowtext"; break;
                }
            }
            else if (c.IsNamedColor) {
                if (c == Color.LightGray) {
                    // special case due to mismatch between Html and enum spelling
                    colorString = "LightGrey";
                }
                else {
                    colorString = c.Name;
                }
            }
            else {
                colorString = "#" + c.R.ToString("X2", null) +
                                    c.G.ToString("X2", null) +
                                    c.B.ToString("X2", null);
            }

            return colorString;
        }
Пример #14
0
        private void FillInternalTable(HtmlTextWriter writer, PeriodOfficeStatistics officeStatistics)
        {
            for (var i = 0; i < officeStatistics.UserStatistics.Length; i++)
            {
                var userStatistic = officeStatistics.UserStatistics[i];
                if (i%2 == 0)
                    writer.WriteLine("<tr class='gridview-row'>");
                else
                    writer.WriteLine("<tr class='gridview-alternatingrow'>");

                foreach (var dayWorkTime in userStatistic.DayWorkTimes)
                {
                    var calendarItem = new CalendarItem(dayWorkTime);
                    var contentValue = DateTimePresenter.GetTime(dayWorkTime.WorkTime);

                    var cellColor = new Color();
                    if (dayWorkTime.WorkTime == TimeSpan.Zero && !calendarItem.IsWeekend)
                    {
                        WorkEvent workEvent = WorkEvent.GetCurrentEventOfDate((int) userStatistic.User.ID, dayWorkTime.Date);

                        if (workEvent != null)
                            switch (workEvent.EventType)
                            {
                                case WorkEventType.BusinessTrip:
                                    contentValue = "Trip";
                                    cellColor = Color.LightSlateGray;
                                    break;

                                case WorkEventType.Ill:
                                    contentValue = "Ill";
                                    cellColor = Color.LightPink;
                                    break;

                                case WorkEventType.TrustIll:
                                    contentValue = "Trust Ill";
                                    cellColor = Color.LightPink;
                                    break;

                                case WorkEventType.Vacation:
                                    contentValue = "Vacation";
                                    cellColor = Color.LightYellow;
                                    break;
                            }
                    }

                    if (calendarItem.IsWeekend)
                        writer.WriteLine("<td class='weekend statistic-table-internal-td'>{0}</td>", contentValue);
                    else
                        writer.WriteLine(
                            "<td class='statistic-table-internal-td' style='background-color: {0};' align='center'>{1}</td>",
                            cellColor.ToKnownColor(),
                            contentValue);
                }

                writer.WriteLine("<td class='statistic-table-internal-td'>{0}</td>",
                    DateTimePresenter.GetTime(userStatistic.TotalWorkTime));
                writer.WriteLine("<td class='statistic-table-internal-td'>{0}</td>",
                    DateTimePresenter.GetTime(userStatistic.RateTime));
                writer.WriteLine("<td class='statistic-table-internal-td'>{0}</td>",
                    DateTimePresenter.GetTime(userStatistic.RateTime - userStatistic.TotalWorkTime));
                writer.WriteLine("<td class='statistic-table-internal-td'>{0}</td>", GetDomainNameByUserStatistic(userStatistic));
                writer.WriteLine("</tr>");
            }
        }
Пример #15
0
	public static Color Dark(Color baseColor, float percOfDarkDark)
			{
				if(baseColor.ToKnownColor() == KnownColor.Control)
				{
					if(percOfDarkDark <= 0.0f)
					{
						return SystemColors.ControlDark;
					}
					else if(percOfDarkDark >= 1.0f)
					{
						return SystemColors.ControlDarkDark;
					}
					else
					{
						Color dark = SystemColors.ControlDark;
						Color darkdark = SystemColors.ControlDarkDark;
						int redDiff = darkdark.R - dark.R;
						int greenDiff = darkdark.G - dark.G;
						int blueDiff = darkdark.B - dark.B;
						return Color.FromArgb
							(dark.R + (int)(redDiff * percOfDarkDark),
							 dark.G + (int)(greenDiff * percOfDarkDark),
							 dark.B + (int)(blueDiff * percOfDarkDark));
					}
				}
				float hue = baseColor.GetHue();
				float saturation = baseColor.GetSaturation();
				float brightness = baseColor.GetBrightness();
				brightness -= brightness * percOfDarkDark * 0.333f;
				if(brightness < 0.0f)
				{
					brightness = 0.0f;
				}
				return FromHSB(hue, saturation, brightness);
			}
Пример #16
0
	public static Color Light(Color baseColor, float percOfLightLight)
			{
				if(baseColor.ToKnownColor() == KnownColor.Control)
				{
					if(percOfLightLight <= 0.0f)
					{
						return SystemColors.ControlLight;
					}
					else if(percOfLightLight >= 1.0f)
					{
						return SystemColors.ControlLightLight;
					}
					else
					{
						Color light = SystemColors.ControlLight;
						Color lightlight = SystemColors.ControlLightLight;
						int redDiff = lightlight.R - light.R;
						int greenDiff = lightlight.G - light.G;
						int blueDiff = lightlight.B - light.B;
						return Color.FromArgb
							(light.R + (int)(redDiff * percOfLightLight),
							 light.G + (int)(greenDiff * percOfLightLight),
							 light.B + (int)(blueDiff * percOfLightLight));
					}
				}
				float hue = baseColor.GetHue();
				float saturation = baseColor.GetSaturation();
				float brightness = baseColor.GetBrightness();
				brightness += brightness * percOfLightLight * 0.5f;
				if(brightness > 1.0f)
				{
					brightness = 1.0f;
				}
				return  FromHSB(hue, saturation, brightness);
			}
        public static int ToOle(Color c)
        {
            if (c.IsKnownColor)
            {
                switch (c.ToKnownColor())
                {
                    case KnownColor.ActiveBorder:
                        return -2147483638;

                    case KnownColor.ActiveCaption:
                        return -2147483646;

                    case KnownColor.ActiveCaptionText:
                        return -2147483639;

                    case KnownColor.AppWorkspace:
                        return -2147483636;

                    case KnownColor.Control:
                        return -2147483633;

                    case KnownColor.ControlDark:
                        return -2147483632;

                    case KnownColor.ControlDarkDark:
                        return -2147483627;

                    case KnownColor.ControlLight:
                        return -2147483626;

                    case KnownColor.ControlLightLight:
                        return -2147483628;

                    case KnownColor.ControlText:
                        return -2147483630;

                    case KnownColor.Desktop:
                        return -2147483647;

                    case KnownColor.GrayText:
                        return -2147483631;

                    case KnownColor.Highlight:
                        return -2147483635;

                    case KnownColor.HighlightText:
                        return -2147483634;

                    case KnownColor.HotTrack:
                        return -2147483622;

                    case KnownColor.InactiveBorder:
                        return -2147483637;

                    case KnownColor.InactiveCaption:
                        return -2147483645;

                    case KnownColor.InactiveCaptionText:
                        return -2147483629;

                    case KnownColor.Info:
                        return -2147483624;

                    case KnownColor.InfoText:
                        return -2147483625;

                    case KnownColor.Menu:
                        return -2147483644;

                    case KnownColor.MenuText:
                        return -2147483641;

                    case KnownColor.ScrollBar:
                        return -2147483648;

                    case KnownColor.Window:
                        return -2147483643;

                    case KnownColor.WindowFrame:
                        return -2147483642;

                    case KnownColor.WindowText:
                        return -2147483640;

                    case KnownColor.ButtonFace:
                        return -2147483633;

                    case KnownColor.ButtonHighlight:
                        return -2147483628;

                    case KnownColor.ButtonShadow:
                        return -2147483632;

                    case KnownColor.GradientActiveCaption:
                        return -2147483621;

                    case KnownColor.GradientInactiveCaption:
                        return -2147483620;

                    case KnownColor.MenuBar:
                        return -2147483618;

                    case KnownColor.MenuHighlight:
                        return -2147483619;
                }
            }
            return ToWin32(c);
        }
        public static string ToHtml(Color c)
        {
            string str = string.Empty;
            if (!c.IsEmpty)
            {
                if (!c.IsSystemColor)
                {
                    if (c.IsNamedColor)
                    {
                        if (c == Color.LightGray)
                        {
                            return "LightGrey";
                        }
                        return c.Name;
                    }
                    return ("#" + c.R.ToString("X2", null) + c.G.ToString("X2", null) + c.B.ToString("X2", null));
                }
                switch (c.ToKnownColor())
                {
                    case KnownColor.ActiveBorder:
                        return "activeborder";

                    case KnownColor.ActiveCaption:
                    case KnownColor.GradientActiveCaption:
                        return "activecaption";

                    case KnownColor.ActiveCaptionText:
                        return "captiontext";

                    case KnownColor.AppWorkspace:
                        return "appworkspace";

                    case KnownColor.Control:
                        return "buttonface";

                    case KnownColor.ControlDark:
                        return "buttonshadow";

                    case KnownColor.ControlDarkDark:
                        return "threeddarkshadow";

                    case KnownColor.ControlLight:
                        return "buttonface";

                    case KnownColor.ControlLightLight:
                        return "buttonhighlight";

                    case KnownColor.ControlText:
                        return "buttontext";

                    case KnownColor.Desktop:
                        return "background";

                    case KnownColor.GrayText:
                        return "graytext";

                    case KnownColor.Highlight:
                    case KnownColor.HotTrack:
                        return "highlight";

                    case KnownColor.HighlightText:
                    case KnownColor.MenuHighlight:
                        return "highlighttext";

                    case KnownColor.InactiveBorder:
                        return "inactiveborder";

                    case KnownColor.InactiveCaption:
                    case KnownColor.GradientInactiveCaption:
                        return "inactivecaption";

                    case KnownColor.InactiveCaptionText:
                        return "inactivecaptiontext";

                    case KnownColor.Info:
                        return "infobackground";

                    case KnownColor.InfoText:
                        return "infotext";

                    case KnownColor.Menu:
                    case KnownColor.MenuBar:
                        return "menu";

                    case KnownColor.MenuText:
                        return "menutext";

                    case KnownColor.ScrollBar:
                        return "scrollbar";

                    case KnownColor.Window:
                        return "window";

                    case KnownColor.WindowFrame:
                        return "windowframe";

                    case KnownColor.WindowText:
                        return "windowtext";
                }
            }
            return str;
        }
		/// <summary>Translates the specified <see cref="T:System.Drawing.Color" /> structure to an HTML string color representation.</summary>
		/// <returns>The string that represents the HTML color.</returns>
		/// <param name="c">The <see cref="T:System.Drawing.Color" /> structure to translate. </param>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet>
		///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
		/// </PermissionSet>
		public static string ToHtml(Color c)
		{
			string result = string.Empty;
			if (c.IsEmpty)
			{
				return result;
			}
			if (c.IsSystemColor)
			{
				KnownColor knownColor = c.ToKnownColor();
				switch (knownColor)
				{
				case KnownColor.ActiveBorder:
					result = "activeborder";
					return result;
				case KnownColor.ActiveCaption:
					break;
				case KnownColor.ActiveCaptionText:
					result = "captiontext";
					return result;
				case KnownColor.AppWorkspace:
					result = "appworkspace";
					return result;
				case KnownColor.Control:
					result = "buttonface";
					return result;
				case KnownColor.ControlDark:
					result = "buttonshadow";
					return result;
				case KnownColor.ControlDarkDark:
					result = "threeddarkshadow";
					return result;
				case KnownColor.ControlLight:
					result = "buttonface";
					return result;
				case KnownColor.ControlLightLight:
					result = "buttonhighlight";
					return result;
				case KnownColor.ControlText:
					result = "buttontext";
					return result;
				case KnownColor.Desktop:
					result = "background";
					return result;
				case KnownColor.GrayText:
					result = "graytext";
					return result;
				case KnownColor.Highlight:
				case KnownColor.HotTrack:
					result = "highlight";
					return result;
				case KnownColor.HighlightText:
					goto IL_12F;
				case KnownColor.InactiveBorder:
					result = "inactiveborder";
					return result;
				case KnownColor.InactiveCaption:
					goto IL_145;
				case KnownColor.InactiveCaptionText:
					result = "inactivecaptiontext";
					return result;
				case KnownColor.Info:
					result = "infobackground";
					return result;
				case KnownColor.InfoText:
					result = "infotext";
					return result;
				case KnownColor.Menu:
					goto IL_171;
				case KnownColor.MenuText:
					result = "menutext";
					return result;
				case KnownColor.ScrollBar:
					result = "scrollbar";
					return result;
				case KnownColor.Window:
					result = "window";
					return result;
				case KnownColor.WindowFrame:
					result = "windowframe";
					return result;
				case KnownColor.WindowText:
					result = "windowtext";
					return result;
				default:
					switch (knownColor)
					{
					case KnownColor.GradientActiveCaption:
						break;
					case KnownColor.GradientInactiveCaption:
						goto IL_145;
					case KnownColor.MenuBar:
						goto IL_171;
					case KnownColor.MenuHighlight:
						goto IL_12F;
					default:
						return result;
					}
					break;
				}
				result = "activecaption";
				return result;
				IL_12F:
				result = "highlighttext";
				return result;
				IL_145:
				result = "inactivecaption";
				return result;
				IL_171:
				result = "menu";
			}
			else if (c.IsNamedColor)
			{
				if (c == Color.LightGray)
				{
					result = "LightGrey";
				}
				else
				{
					result = c.Name;
				}
			}
			else
			{
				result = "#" + c.R.ToString("X2", null) + c.G.ToString("X2", null) + c.B.ToString("X2", null);
			}
			return result;
		}
Пример #20
0
		public static string ToHtml (Color c)
		{
			if (c.IsEmpty)
				return String.Empty;

			if (c.IsSystemColor) {
				KnownColor kc = c.ToKnownColor ();
				switch (kc) {
				case KnownColor.ActiveBorder:
				case KnownColor.ActiveCaption:
				case KnownColor.AppWorkspace:
				case KnownColor.GrayText:
				case KnownColor.Highlight:
				case KnownColor.HighlightText:
				case KnownColor.InactiveBorder:
				case KnownColor.InactiveCaption:
				case KnownColor.InactiveCaptionText:
				case KnownColor.InfoText:
				case KnownColor.Menu:
				case KnownColor.MenuText:
				case KnownColor.ScrollBar:
				case KnownColor.Window:
				case KnownColor.WindowFrame:
				case KnownColor.WindowText:
					return KnownColors.GetName (kc).ToLower (CultureInfo.InvariantCulture);

				case KnownColor.ActiveCaptionText:
					return "captiontext";
				case KnownColor.Control:
					return "buttonface";
				case KnownColor.ControlDark:
					return "buttonshadow";
				case KnownColor.ControlDarkDark:
					return "threeddarkshadow";
				case KnownColor.ControlLight:
					return "buttonface";
				case KnownColor.ControlLightLight:
					return "buttonhighlight";
				case KnownColor.ControlText:
					return "buttontext";
				case KnownColor.Desktop:
					return "background";
				case KnownColor.HotTrack:
					return "highlight";
				case KnownColor.Info:
					return "infobackground";

				default:
					return String.Empty;
				}
			}

			if (c.IsNamedColor) {
				if (c == Color.LightGray)
					return "LightGrey";
				else
					return c.Name;
			}

			return FormatHtml (c.R, c.G, c.B);
		}
Пример #21
0
        /// <devdoc>
        ///     Helper function that draws a more complex border.  This is used by DrawBorder for less common
        ///     rendering cases.  We split DrawBorder into DrawBorderSimple and DrawBorderComplex so we maximize
        ///     the % of the function call.  It is less performant to have large functions that do many things.
        /// </devdoc>
        private static void DrawBorderComplex(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style) {
            if (graphics == null) {
                throw new ArgumentNullException("graphics");
            }
            if (style == ButtonBorderStyle.Inset) { // button being pushed
                HLSColor hls = new HLSColor(color);

                // top + left
                Pen pen = new Pen(hls.Darker(1.0f));
                graphics.DrawLine(pen, bounds.X, bounds.Y, 
                                  bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(pen, bounds.X, bounds.Y, 
                                  bounds.X, bounds.Y + bounds.Height - 1);

                // bottom + right
                pen.Color = hls.Lighter(1.0f);
                graphics.DrawLine(pen, bounds.X, bounds.Y + bounds.Height - 1, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(pen, bounds.X + bounds.Width - 1, bounds.Y, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);

                // Top + left inset
                pen.Color = hls.Lighter(0.5f);
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                      bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                  bounds.X + 1, bounds.Y + bounds.Height - 2);

                // bottom + right inset
                if (color.ToKnownColor() == SystemColors.Control.ToKnownColor()) {
                    pen.Color = SystemColors.ControlLight;
                    graphics.DrawLine(pen, bounds.X + 1, bounds.Y + bounds.Height - 2,
                                              bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                    graphics.DrawLine(pen, bounds.X + bounds.Width - 2, bounds.Y + 1,
                                      bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                }

                pen.Dispose();
            }
            else { // Standard button
                Debug.Assert(style == ButtonBorderStyle.Outset, "Caller should have known how to use us.");
                
                bool stockColor = color.ToKnownColor() == SystemColors.Control.ToKnownColor();
                HLSColor hls = new HLSColor(color);

                // top + left
                Pen pen = stockColor ? SystemPens.ControlLightLight : new Pen(hls.Lighter(1.0f));
                graphics.DrawLine(pen, bounds.X, bounds.Y,
                                            bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(pen, bounds.X, bounds.Y, 
                                  bounds.X, bounds.Y + bounds.Height - 1);
                // bottom + right
                if (stockColor) {
                    pen = SystemPens.ControlDarkDark;
                }
                else {
                    pen.Color = hls.Darker(1.0f);
                }
                graphics.DrawLine(pen, bounds.X, bounds.Y + bounds.Height - 1, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(pen, bounds.X + bounds.Width - 1, bounds.Y, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                // top + left inset
                if (stockColor) {
                    if (SystemInformation.HighContrast) {
                        pen = SystemPens.ControlLight;
                    }
                    else {
                        pen = SystemPens.Control;
                    }
                }
                else {
                    pen.Color = color;
                }
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                  bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                  bounds.X + 1, bounds.Y + bounds.Height - 2);

                // Bottom + right inset                        
                if (stockColor) {
                    pen = SystemPens.ControlDark;
                }
                else {
                    pen.Color = hls.Darker(0.5f);
                }

                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + bounds.Height - 2,
                                  bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                graphics.DrawLine(pen, bounds.X + bounds.Width - 2, bounds.Y + 1,
                                  bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                                  
                if (!stockColor) {
                    pen.Dispose();
                }
            }
        }
Пример #22
0
        public static string ToHtml(Color c)
        {
            if (c.IsEmpty)
            {
                return(String.Empty);
            }

            if (c.IsSystemColor)
            {
                KnownColor kc = c.ToKnownColor();
                switch (kc)
                {
                case KnownColor.ActiveBorder:
                case KnownColor.ActiveCaption:
                case KnownColor.AppWorkspace:
                case KnownColor.GrayText:
                case KnownColor.Highlight:
                case KnownColor.HighlightText:
                case KnownColor.InactiveBorder:
                case KnownColor.InactiveCaption:
                case KnownColor.InactiveCaptionText:
                case KnownColor.InfoText:
                case KnownColor.Menu:
                case KnownColor.MenuText:
                case KnownColor.ScrollBar:
                case KnownColor.Window:
                case KnownColor.WindowFrame:
                case KnownColor.WindowText:
                    return(KnownColors.GetName(kc).ToLowerInvariant());

                case KnownColor.ActiveCaptionText:
                    return("captiontext");

                case KnownColor.Control:
                    return("buttonface");

                case KnownColor.ControlDark:
                    return("buttonshadow");

                case KnownColor.ControlDarkDark:
                    return("threeddarkshadow");

                case KnownColor.ControlLight:
                    return("buttonface");

                case KnownColor.ControlLightLight:
                    return("buttonhighlight");

                case KnownColor.ControlText:
                    return("buttontext");

                case KnownColor.Desktop:
                    return("background");

                case KnownColor.HotTrack:
                    return("highlight");

                case KnownColor.Info:
                    return("infobackground");

                default:
                    return(String.Empty);
                }
            }

            if (c.IsNamedColor)
            {
                if (c == Color.LightGray)
                {
                    return("LightGrey");
                }
                else
                {
                    return(c.Name);
                }
            }

            return(FormatHtml(c.R, c.G, c.B));
        }
 public HLSColor(Color color)
 {
     this.isSystemColors_Control = color.ToKnownColor() == SystemColors.Control.ToKnownColor();
     int r = color.R;
     int g = color.G;
     int b = color.B;
     int num4 = Math.Max(Math.Max(r, g), b);
     int num5 = Math.Min(Math.Min(r, g), b);
     int num6 = num4 + num5;
     this.luminosity = ((num6 * 240) + 0xff) / 510;
     int num7 = num4 - num5;
     if (num7 == 0)
     {
         this.saturation = 0;
         this.hue = 160;
     }
     else
     {
         if (this.luminosity <= 120)
         {
             this.saturation = ((num7 * 240) + (num6 / 2)) / num6;
         }
         else
         {
             this.saturation = ((num7 * 240) + ((510 - num6) / 2)) / (510 - num6);
         }
         int num8 = (((num4 - r) * 40) + (num7 / 2)) / num7;
         int num9 = (((num4 - g) * 40) + (num7 / 2)) / num7;
         int num10 = (((num4 - b) * 40) + (num7 / 2)) / num7;
         if (r == num4)
         {
             this.hue = num10 - num9;
         }
         else if (g == num4)
         {
             this.hue = (80 + num8) - num10;
         }
         else
         {
             this.hue = (160 + num9) - num8;
         }
         if (this.hue < 0)
         {
             this.hue += 240;
         }
         if (this.hue > 240)
         {
             this.hue -= 240;
         }
     }
 }
Пример #24
0
 private void UpdateItemColor(int itemIndex, int subItemIndex, Color fore, Color back)
 {
     if (lvAttributes.Items.Count <= itemIndex || lvAttributes.Items[itemIndex].SubItems.Count <= subItemIndex)
         return;
     if (fore.ToKnownColor() == (KnownColor)0)
         fore = AttrData.defaultForeground;
     lvAttributes.Items[itemIndex].SubItems[subItemIndex].ForeColor = fore;
     if (back.ToKnownColor() == (KnownColor)0)
         back = AttrData.defaultBackground;
     lvAttributes.Items[itemIndex].SubItems[subItemIndex].BackColor = back;
 }
Пример #25
0
 private void UpdateItemColor(ListViewItem.ListViewSubItem lvSubItem, Color fore, Color back)
 {
     if (lvSubItem == null)
         return;
     if (fore.ToKnownColor() == (KnownColor)0)
         fore = AttrData.defaultForeground;
     lvSubItem.ForeColor = fore;
     if (back.ToKnownColor() == (KnownColor)0)
         back = AttrData.defaultBackground;
     lvSubItem.BackColor = back;
 }
        /// <include file='doc\ColorTranslator.uex' path='docs/doc[@for="ColorTranslator.ToOle"]/*' />
        /// <devdoc>
        ///    Translates the specified <see cref='System.Drawing.Color'/> to
        ///    an Ole color.
        /// </devdoc>
        public static int ToOle(Color c) {
            //    WARNING!!! WARNING!!! WARNING!!! WARNING!!! 
            //    WARNING!!! WARNING!!! WARNING!!! WARNING!!!
            //    We must never have another method called ToOle() with a different signature.
            //    This is so that we can push into the runtime a custom marshaller for OLE_COLOR to Color.
            
            if (c.IsKnownColor) {
                switch (c.ToKnownColor()) {
                    case KnownColor.ActiveBorder:
                        return unchecked((int)0x8000000A);
                    case KnownColor.ActiveCaption:
                        return unchecked((int)0x80000002);
                    case KnownColor.ActiveCaptionText:
                        return unchecked((int)0x80000009);
                    case KnownColor.AppWorkspace:
                        return unchecked((int)0x8000000C);
                    case KnownColor.ButtonFace:
                        return unchecked((int)0x8000000F);
                    case KnownColor.ButtonHighlight:
                        return unchecked((int)0x80000014);
                    case KnownColor.ButtonShadow:
                        return unchecked((int)0x80000010);
                    case KnownColor.Control:
                        return unchecked((int)0x8000000F);
                    case KnownColor.ControlDark:
                        return unchecked((int)0x80000010);
                    case KnownColor.ControlDarkDark:
                        return unchecked((int)0x80000015);
                    case KnownColor.ControlLight:
                        return unchecked((int)0x80000016);
                    case KnownColor.ControlLightLight:
                        return unchecked((int)0x80000014);
                    case KnownColor.ControlText:
                        return unchecked((int)0x80000012);
                    case KnownColor.Desktop:
                        return unchecked((int)0x80000001);
                    case KnownColor.GradientActiveCaption:
                        return unchecked((int)0x8000001B);
                    case KnownColor.GradientInactiveCaption:
                        return unchecked((int)0x8000001C);
                    case KnownColor.GrayText:
                        return unchecked((int)0x80000011);
                    case KnownColor.Highlight:
                        return unchecked((int)0x8000000D);
                    case KnownColor.HighlightText:
                        return unchecked((int)0x8000000E);
                    case KnownColor.HotTrack:
                        return unchecked((int)0x8000001A);
                    case KnownColor.InactiveBorder:
                        return unchecked((int)0x8000000B);
                    case KnownColor.InactiveCaption:
                        return unchecked((int)0x80000003);
                    case KnownColor.InactiveCaptionText:
                        return unchecked((int)0x80000013);
                    case KnownColor.Info:
                        return unchecked((int)0x80000018);
                    case KnownColor.InfoText:
                        return unchecked((int)0x80000017);
                    case KnownColor.Menu:
                        return unchecked((int)0x80000004);
                    case KnownColor.MenuBar:
                        return unchecked((int)0x8000001E);
                    case KnownColor.MenuHighlight:
                        return unchecked((int)0x8000001D);
                    case KnownColor.MenuText:
                        return unchecked((int)0x80000007);
                    case KnownColor.ScrollBar:
                        return unchecked((int)0x80000000);
                    case KnownColor.Window:
                        return unchecked((int)0x80000005);
                    case KnownColor.WindowFrame:
                        return unchecked((int)0x80000006);
                    case KnownColor.WindowText:
                        return unchecked((int)0x80000008);
                }
            }

            return ToWin32(c);
        }
Пример #27
0
        private void prepWriteDispBoxes(Data msg, Color newColor)
        {
            string msgText = msg.strMessage;
            textToDisp = new string[3];
            textToDisp[0] = "";
            textToDisp[1] = "";
            textToDisp[2] = "";
            clearDispMsg();
            if (newColor.ToKnownColor() != KnownColor.PeachPuff)
                setDispMsgColor(newColor);

            msgText = msg.strMessage.Substring(msg.strName.Length + 2);

            for (int i = 0; i < 3; i++)
            {
                if (TextRenderer.MeasureText(msgText, displayMsg1.Font).Width > 240)
                {
                    string[] parts = msgText.Split(' ');
                    string combined = "";
                    for (int x = 0; x < parts.Length; x++)
                    {
                        /* if (i == 2) // test bit of code to try and help me test these stupid loops
                        {
                            string test = "";
                        } */

                        //TO DO: Add a handler in case a single word is too long, and measure it by characters
                        if (TextRenderer.MeasureText(parts[x], displayMsg1.Font).Width <= 246)
                        {
                            if (TextRenderer.MeasureText(combined + parts[x] + " ", displayMsg1.Font).Width <= 246)
                            {
                                combined = combined + parts[x] + " "; // TO DO: Don't add a space after the last word
                            }
                            else
                            {
                                textToDisp[i] = combined;
                                msgText = msgText.Substring(combined.Length);
                                break;
                            }
                        }
                        else
                        {
                            for (int y = 0; y < parts[x].Length; y++)
                            {
                                if (TextRenderer.MeasureText(combined + parts[x].Substring(0, y), displayMsg1.Font).Width <= 246)
                                {
                                    combined = combined + parts[x].Substring(0, y); // TO DO: Don't add a space after the last word
                                }
                                else
                                {
                                    textToDisp[i] = combined;
                                    msgText = msgText.Substring(combined.Length);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    textToDisp[i] = msgText;
                    break;
                }
            }
            //dispTextRedraw.Enabled = true;
            nameLabel.Text = iniParser.GetDispName(latestMsg.strName) ?? latestMsg.strName;
            //blipPlayer.Initialize(blipReader);
            blipPlayer.Stop();
            if (!mute)
                blipPlayer.Play();
            redraw = true;
        }
Пример #28
0
        public static Pen FromSystemColor(Color c) {
            if (!c.IsSystemColor) {
                throw new ArgumentException(SR.GetString(SR.ColorNotSystemColor, c.ToString()));
            }
            
            Pen[] systemPens = (Pen[])SafeNativeMethods.Gdip.ThreadData[SystemPensKey];
            if (systemPens == null) {        
                systemPens = new Pen[(int)KnownColor.WindowText + (int)KnownColor.MenuHighlight - (int)KnownColor.YellowGreen];
                SafeNativeMethods.Gdip.ThreadData[SystemPensKey] = systemPens;
            }

            int idx = (int)c.ToKnownColor();
            if (idx > (int)KnownColor.YellowGreen) {
                idx -= (int)KnownColor.YellowGreen - (int)KnownColor.WindowText;
            }
            idx--;
            Debug.Assert(idx >= 0 && idx < systemPens.Length, "System colors have been added but our system color array has not been expanded.");
            
            if (systemPens[idx] == null) {
                systemPens[idx] = new Pen(c, true);
            }
            
            return systemPens[idx];
        }
Пример #29
0
        /// <summary>
        /// Translates the specified <see cref='Color'/> to an Html string color representation.
        /// </summary>
        public static string ToHtml(Color c)
        {
            string colorString = string.Empty;

            if (c.IsEmpty)
            {
                return(colorString);
            }

            if (c.IsSystemColor)
            {
                switch (c.ToKnownColor())
                {
                case KnownColor.ActiveBorder:
                    colorString = "activeborder";
                    break;

                case KnownColor.GradientActiveCaption:
                case KnownColor.ActiveCaption:
                    colorString = "activecaption";
                    break;

                case KnownColor.AppWorkspace:
                    colorString = "appworkspace";
                    break;

                case KnownColor.Desktop:
                    colorString = "background";
                    break;

                case KnownColor.Control:
                case KnownColor.ControlLight:
                    colorString = "buttonface";
                    break;

                case KnownColor.ControlDark:
                    colorString = "buttonshadow";
                    break;

                case KnownColor.ControlText:
                    colorString = "buttontext";
                    break;

                case KnownColor.ActiveCaptionText:
                    colorString = "captiontext";
                    break;

                case KnownColor.GrayText:
                    colorString = "graytext";
                    break;

                case KnownColor.HotTrack:
                case KnownColor.Highlight:
                    colorString = "highlight";
                    break;

                case KnownColor.MenuHighlight:
                case KnownColor.HighlightText:
                    colorString = "highlighttext";
                    break;

                case KnownColor.InactiveBorder:
                    colorString = "inactiveborder";
                    break;

                case KnownColor.GradientInactiveCaption:
                case KnownColor.InactiveCaption:
                    colorString = "inactivecaption";
                    break;

                case KnownColor.InactiveCaptionText:
                    colorString = "inactivecaptiontext";
                    break;

                case KnownColor.Info:
                    colorString = "infobackground";
                    break;

                case KnownColor.InfoText:
                    colorString = "infotext";
                    break;

                case KnownColor.MenuBar:
                case KnownColor.Menu:
                    colorString = "menu";
                    break;

                case KnownColor.MenuText:
                    colorString = "menutext";
                    break;

                case KnownColor.ScrollBar:
                    colorString = "scrollbar";
                    break;

                case KnownColor.ControlDarkDark:
                    colorString = "threeddarkshadow";
                    break;

                case KnownColor.ControlLightLight:
                    colorString = "buttonhighlight";
                    break;

                case KnownColor.Window:
                    colorString = "window";
                    break;

                case KnownColor.WindowFrame:
                    colorString = "windowframe";
                    break;

                case KnownColor.WindowText:
                    colorString = "windowtext";
                    break;
                }
            }
            else if (c.IsNamedColor)
            {
                if (c == Color.LightGray)
                {
                    // special case due to mismatch between Html and enum spelling
                    colorString = "LightGrey";
                }
                else
                {
                    colorString = c.Name;
                }
            }
            else
            {
                colorString = "#" + c.R.ToString("X2", null) +
                              c.G.ToString("X2", null) +
                              c.B.ToString("X2", null);
            }

            return(colorString);
        }
Пример #30
0
        /// <summary>
        /// Translates the specified <see cref='Color'/> to an Ole color.
        /// </summary>
        public static int ToOle(Color c)
        {
            //    WARNING!!! WARNING!!! WARNING!!! WARNING!!!
            //    WARNING!!! WARNING!!! WARNING!!! WARNING!!!
            //    We must never have another method called ToOle() with a different signature.
            //    This is so that we can push into the runtime a custom marshaller for OLE_COLOR to Color.

            if (ColorUtil.GetIsKnownColor(c))
            {
                switch (c.ToKnownColor())
                {
                case KnownColor.ActiveBorder:
                    return(unchecked ((int)0x8000000A));

                case KnownColor.ActiveCaption:
                    return(unchecked ((int)0x80000002));

                case KnownColor.ActiveCaptionText:
                    return(unchecked ((int)0x80000009));

                case KnownColor.AppWorkspace:
                    return(unchecked ((int)0x8000000C));

                case KnownColor.ButtonFace:
                    return(unchecked ((int)0x8000000F));

                case KnownColor.ButtonHighlight:
                    return(unchecked ((int)0x80000014));

                case KnownColor.ButtonShadow:
                    return(unchecked ((int)0x80000010));

                case KnownColor.Control:
                    return(unchecked ((int)0x8000000F));

                case KnownColor.ControlDark:
                    return(unchecked ((int)0x80000010));

                case KnownColor.ControlDarkDark:
                    return(unchecked ((int)0x80000015));

                case KnownColor.ControlLight:
                    return(unchecked ((int)0x80000016));

                case KnownColor.ControlLightLight:
                    return(unchecked ((int)0x80000014));

                case KnownColor.ControlText:
                    return(unchecked ((int)0x80000012));

                case KnownColor.Desktop:
                    return(unchecked ((int)0x80000001));

                case KnownColor.GradientActiveCaption:
                    return(unchecked ((int)0x8000001B));

                case KnownColor.GradientInactiveCaption:
                    return(unchecked ((int)0x8000001C));

                case KnownColor.GrayText:
                    return(unchecked ((int)0x80000011));

                case KnownColor.Highlight:
                    return(unchecked ((int)0x8000000D));

                case KnownColor.HighlightText:
                    return(unchecked ((int)0x8000000E));

                case KnownColor.HotTrack:
                    return(unchecked ((int)0x8000001A));

                case KnownColor.InactiveBorder:
                    return(unchecked ((int)0x8000000B));

                case KnownColor.InactiveCaption:
                    return(unchecked ((int)0x80000003));

                case KnownColor.InactiveCaptionText:
                    return(unchecked ((int)0x80000013));

                case KnownColor.Info:
                    return(unchecked ((int)0x80000018));

                case KnownColor.InfoText:
                    return(unchecked ((int)0x80000017));

                case KnownColor.Menu:
                    return(unchecked ((int)0x80000004));

                case KnownColor.MenuBar:
                    return(unchecked ((int)0x8000001E));

                case KnownColor.MenuHighlight:
                    return(unchecked ((int)0x8000001D));

                case KnownColor.MenuText:
                    return(unchecked ((int)0x80000007));

                case KnownColor.ScrollBar:
                    return(unchecked ((int)0x80000000));

                case KnownColor.Window:
                    return(unchecked ((int)0x80000005));

                case KnownColor.WindowFrame:
                    return(unchecked ((int)0x80000006));

                case KnownColor.WindowText:
                    return(unchecked ((int)0x80000008));
                }
            }

            return(ToWin32(c));
        }
	// Draw a simple button border.
	public virtual void DrawBorder
				(Graphics graphics, Rectangle bounds,
				 Color color, ButtonBorderStyle style)
			{
				Pen pen;
				switch(style)
				{
					case ButtonBorderStyle.Dotted:
					{
						pen = new Pen(color, 1.0f);
						pen.EndCap = LineCap.Square;
						pen.DashStyle = DashStyle.Dot;
						graphics.DrawRectangle(pen, bounds);
						pen.Dispose();
					}
					break;

					case ButtonBorderStyle.Dashed:
					{
						pen = new Pen(color, 1.0f);
						pen.EndCap = LineCap.Square;
						pen.DashStyle = DashStyle.Dash;
						graphics.DrawRectangle(pen, bounds);
						pen.Dispose();
					}
					break;

					case ButtonBorderStyle.Solid:
					{
						pen = new Pen(color, 1.0f);
						pen.EndCap = LineCap.Square;
						Rectangle r = new Rectangle(bounds.X,
							bounds.Y, bounds.Width - 1, bounds.Height - 1);
						graphics.DrawRectangle(pen, r);
						pen.Color = ControlPaint.LightLight(color);
						graphics.DrawLine(pen, bounds.X + 1,
							bounds.Y + bounds.Height - 1,
							bounds.X + bounds.Width - 1,
							bounds.Y + bounds.Height - 1);
						graphics.DrawLine(pen, bounds.X + bounds.Width - 1,
							bounds.Y + bounds.Height - 2,
							bounds.X + bounds.Width - 1,
							bounds.Y + 1);
						pen.Dispose();
					}
					break;

					case ButtonBorderStyle.Inset:
					{
						pen = new Pen(ControlPaint.DarkDark(color), 1.0f);
						pen.EndCap = LineCap.Square;
						graphics.DrawLine(pen, bounds.X,
										  bounds.Y + bounds.Height - 1,
										  bounds.X, bounds.Y);
						graphics.DrawLine(pen, bounds.X + 1, bounds.Y,
										  bounds.X + bounds.Width - 1,
										  bounds.Y);
						pen.Color = ControlPaint.LightLight(color);
						graphics.DrawLine(pen, bounds.X + 1,
										  bounds.Y + bounds.Height - 1,
										  bounds.X + bounds.Width - 1,
										  bounds.Y + bounds.Height - 1);
						graphics.DrawLine(pen, bounds.X + bounds.Width - 1,
										  bounds.Y + bounds.Height - 2,
										  bounds.X + bounds.Width - 1,
										  bounds.Y + 1);
						pen.Color = ControlPaint.Light(color);
						graphics.DrawLine(pen, bounds.X + 1,
										  bounds.Y + bounds.Height - 2,
										  bounds.X + 1, bounds.Y + 1);
						graphics.DrawLine(pen, bounds.X + 2, bounds.Y + 1,
										  bounds.X + bounds.Width - 2,
										  bounds.Y + 1);
						if(color.ToKnownColor() == KnownColor.Control)
						{
							pen.Color = SystemColors.ControlLight;
							graphics.DrawLine(pen, bounds.X + 1,
											  bounds.Y + bounds.Height - 2,
											  bounds.X + bounds.Width - 2,
											  bounds.Y + bounds.Height - 2);
							graphics.DrawLine(pen, bounds.X + bounds.Width - 2,
											  bounds.Y + bounds.Height - 3,
											  bounds.X + bounds.Width - 2,
											  bounds.Y + 1);
						}
						pen.Dispose();
					}
					break;

					case ButtonBorderStyle.Outset:
					{
						pen = new Pen(ControlPaint.LightLight(color), 1.0f);
						pen.EndCap = LineCap.Square;
						graphics.DrawLine(pen, bounds.X,
										  bounds.Y + bounds.Height - 2,
										  bounds.X, bounds.Y);
						graphics.DrawLine(pen, bounds.X + 1, bounds.Y,
										  bounds.X + bounds.Width - 2,
										  bounds.Y);
						pen.Color = ControlPaint.DarkDark(color);
						graphics.DrawLine(pen, bounds.X,
										  bounds.Y + bounds.Height - 1,
										  bounds.X + bounds.Width - 1,
										  bounds.Y + bounds.Height - 1);
						graphics.DrawLine(pen, bounds.X + bounds.Width - 1,
										  bounds.Y + bounds.Height - 2,
										  bounds.X + bounds.Width - 1,
										  bounds.Y);
						pen.Color = ControlPaint.Light(color);
						graphics.DrawLine(pen, bounds.X + 1,
										  bounds.Y + bounds.Height - 3,
										  bounds.X + 1, bounds.Y + 1);
						graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
										  bounds.X + bounds.Width - 3,
										  bounds.Y + 1);
						pen.Color = ControlPaint.Dark(color);
						graphics.DrawLine(pen, bounds.X + 1,
										  bounds.Y + bounds.Height - 2,
										  bounds.X + bounds.Width - 2,
										  bounds.Y + bounds.Height - 2);
						graphics.DrawLine(pen, bounds.X + bounds.Width - 2,
										  bounds.Y + bounds.Height - 3,
										  bounds.X + bounds.Width - 2,
										  bounds.Y + 1);
						pen.Dispose();
					}
					break;
				}
			}
 private static void DrawBorderComplex(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (style == ButtonBorderStyle.Inset)
     {
         HLSColor color2 = new HLSColor(color);
         Pen pen = new Pen(color2.Darker(1f));
         graphics.DrawLine(pen, bounds.X, bounds.Y, (bounds.X + bounds.Width) - 1, bounds.Y);
         graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X, (bounds.Y + bounds.Height) - 1);
         pen.Color = color2.Lighter(1f);
         graphics.DrawLine(pen, bounds.X, (bounds.Y + bounds.Height) - 1, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         graphics.DrawLine(pen, (bounds.X + bounds.Width) - 1, bounds.Y, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         pen.Color = color2.Lighter(0.5f);
         graphics.DrawLine(pen, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1));
         graphics.DrawLine(pen, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2));
         if (color.ToKnownColor() == SystemColors.Control.ToKnownColor())
         {
             pen.Color = SystemColors.ControlLight;
             graphics.DrawLine(pen, (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
             graphics.DrawLine(pen, (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
         }
         pen.Dispose();
     }
     else
     {
         bool flag = color.ToKnownColor() == SystemColors.Control.ToKnownColor();
         HLSColor color3 = new HLSColor(color);
         Pen controlDarkDark = flag ? SystemPens.ControlLightLight : new Pen(color3.Lighter(1f));
         graphics.DrawLine(controlDarkDark, bounds.X, bounds.Y, (bounds.X + bounds.Width) - 1, bounds.Y);
         graphics.DrawLine(controlDarkDark, bounds.X, bounds.Y, bounds.X, (bounds.Y + bounds.Height) - 1);
         if (flag)
         {
             controlDarkDark = SystemPens.ControlDarkDark;
         }
         else
         {
             controlDarkDark.Color = color3.Darker(1f);
         }
         graphics.DrawLine(controlDarkDark, bounds.X, (bounds.Y + bounds.Height) - 1, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         graphics.DrawLine(controlDarkDark, (bounds.X + bounds.Width) - 1, bounds.Y, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         if (flag)
         {
             if (SystemInformation.HighContrast)
             {
                 controlDarkDark = SystemPens.ControlLight;
             }
             else
             {
                 controlDarkDark = SystemPens.Control;
             }
         }
         else
         {
             controlDarkDark.Color = color;
         }
         graphics.DrawLine(controlDarkDark, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1));
         graphics.DrawLine(controlDarkDark, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2));
         if (flag)
         {
             controlDarkDark = SystemPens.ControlDark;
         }
         else
         {
             controlDarkDark.Color = color3.Darker(0.5f);
         }
         graphics.DrawLine(controlDarkDark, (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
         graphics.DrawLine(controlDarkDark, (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
         if (!flag)
         {
             controlDarkDark.Dispose();
         }
     }
 }
        /// <summary>
        /// Formats a color instance to a code expression.
        /// </summary>
        /// <param name="color">The color to format.</param>
        /// <returns>A code expression referencing to a property defined in the <see cref="System.Drawing.Color"/> class, 
        /// a call to <see cref="System.Drawing.Color.FromKnownColor(KnownColor)"/>, or a call to 
        /// <see cref="System.Drawing.Color.FromArgb(Int32,Int32,Int32)"/>.</returns>
        public static CodeExpression FormatColor(Color color)
        {
            var colorTypeExpression = new CodeTypeReferenceExpression(typeof(Color));

            if (color.IsKnownColor)
                return new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(colorTypeExpression, "FromKnownColor"), 
                    new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(KnownColor)), color.ToKnownColor().ToString()));
            
            if (color.IsNamedColor)
                return new CodePropertyReferenceExpression(colorTypeExpression, color.Name);
            
            return new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(colorTypeExpression, "FromArgb"),
                new CodePrimitiveExpression(color.A), 
                new CodePrimitiveExpression(color.R), 
                new CodePrimitiveExpression(color.G), 
                new CodePrimitiveExpression(color.B));
        }