当前位置: 首页>>代码示例>>C#>>正文


C# Color.ToArgb方法代码示例

本文整理汇总了C#中System.Drawing.Color.ToArgb方法的典型用法代码示例。如果您正苦于以下问题:C# Color.ToArgb方法的具体用法?C# Color.ToArgb怎么用?C# Color.ToArgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Color的用法示例。


在下文中一共展示了Color.ToArgb方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToArgbToStringExample1

public void ToArgbToStringExample1(PaintEventArgs e)
      {
          Graphics     g = e.Graphics;
                   
          // Color structure used for temporary storage.
          Color   someColor = Color.FromArgb(0);
                   
          // Array to store KnownColor values that match the criteria.
          KnownColor[]  colorMatches = new KnownColor[167];
          
          // Number of matches found.
          int  count = 0; 

          // Iterate through the KnownColor enums to find all corresponding colors
          // that have a nonzero green component and zero-value red component and
          // that are not system colors.
          for (KnownColor enumValue = 0;
              enumValue <= KnownColor.YellowGreen; enumValue++)
          {
              someColor = Color.FromKnownColor(enumValue);
              if (someColor.G != 0 && someColor.R == 0 && !someColor.IsSystemColor)
                  colorMatches[count++] = enumValue;
          }
          SolidBrush  myBrush1 = new SolidBrush(someColor);
          Font        myFont = new Font("Arial", 9);
          int         x = 40;
          int         y = 40;
                   
          // Iterate through the matches that were found and display each color that
          // corresponds with the enum value in the array. also display the name of
          // the KnownColor and the ARGB components.
          for (int i = 0; i < count; i++)
          {
                   
              // Display the color.
              someColor = Color.FromKnownColor(colorMatches[i]);
              myBrush1.Color = someColor;
              g.FillRectangle(myBrush1, x, y, 50, 30);
                   
              // Display KnownColor name and the four component values. To display the
              // component values:  Use the ToArgb method to get the 32-bit ARGB value
              // of someColor, which was created from a KnownColor. Then create a
              // Color structure from the 32-bit ARGB value and set someColor equal to
              // this new Color structure. Then use the ToString method to convert it to
              // a string.
              g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 55, y);
              someColor = Color.FromArgb(someColor.ToArgb());
              g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 55, y + 15);
              y += 40;
          }
      }
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:51,代码来源:Color.ToArgb


注:本文中的System.Drawing.Color.ToArgb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。