[C #] generating a predefined full-color table

Source: Internet
Author: User

Generate a Color table for all static predefined members of the Color class.

Const long CELLS_PER_LINE = 10; const float MARGIN = 12; const float CELL_WIDTH = 160; const float CELL_HEIGHT = 64; const float COLOR_LEFT_MARGIN = 8; const float COLOR_TOP_MARGIN = 8; const float COLOR_CELL_WIDTH = 48; const float COLOR_CELL_HEIGHT = 32; const float TEXT_TOP_MARGIN = COLOR_TOP_MARGIN + COLOR_CELL_HEIGHT + 2; List <Color> vColors = new List <Color> (); type t = typeof (Color); PropertyInfo [] vProps = t. getProperties (); foreach (PropertyInfo propInfo in vProps) {if (MemberTypes. property = propInfo. memberType & typeof (Color) = propInfo. propertyType) {Color tmpColor = (Color) propInfo. getValue (null, null); vColors. add (tmpColor) ;}} Bitmap BMP color = new Bitmap (int) (CELLS_PER_LINE * CELL_WIDTH + MARGIN * 2), (int) (vColors. count/CELLS_PER_LINE + 1) * CELL_HEIGHT + MARGIN * 2); using (Graphics grp = Graphics. fromImage (BMP color) {grp. clear (Color. black); for (int I = 0; I <vColors. count; I ++) {float nLeftBase = MARGIN + I % CELLS_PER_LINE * CELL_WIDTH; float nTopBase = MARGIN + I/CELLS_PER_LINE * CELL_HEIGHT; grp. drawRectangle (new Pen (Color. white), nLeftBase, nTopBase, CELL_WIDTH, CELL_HEIGHT); grp. fillRectangle (new SolidBrush (vColors [I]), nLeftBase + COLOR_LEFT_MARGIN, nTopBase + COLOR_TOP_MARGIN, COLOR_CELL_WIDTH, COLOR_CELL_HEIGHT); grp. drawString (vColors [I]. name, new Font ("", 9, FontStyle. regular), new SolidBrush (Color. white), nLeftBase + COLOR_LEFT_MARGIN, nTopBase + TEXT_TOP_MARGIN) ;}} BMP color. save (@ "D: \ AllColor.bmp ");

 

Generate results

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.