Use reflection to enumerate HatchStyle values and display samples of them in C#


reflection

The post Use reflection to easily list the values defined by an enumerated type in C# shows one way to list the values in an enumeration. This example uses that technique in the following code to enumerate the HatchStyle values.

// Display the names and samples of the HatchStyle values.
private void Form1_Load(object sender, EventArgs e)
{
    // Get a list of the HatchStyles.
    List<HatchStyle> hatch_styles = GetEnumValues<HatchStyle>();
    foreach (HatchStyle hatch_style in hatch_styles)
    {
        DisplayHatchStyle(hatch_style);
    }
}

For each HatchStyle, this code calls the DisplayHatchStyle method. That method displays the HatchStyle names and samples in a Panel and adds the Panel to the program’s FlowLayoutPanel. See the example Display images of the cursors available in C# for details about that technique.


Download Example   Follow me on Twitter   RSS feed




This entry was posted in enums, graphics, reflection, syntax and tagged , , , , , , , , , , . Bookmark the permalink.

2 Responses to Use reflection to enumerate HatchStyle values and display samples of them in C#

  1. Oliver Bock says:

    Good stuff. Think you have put BM_WID where you meant BM_HGT at lines 81 & 95.

  2. Rod Stephens says:

    Hi Oliver,

    You’re right. By coincidence, the program was only copying part of the image into a different image and displaying the image in a smaller PictureBox. Although the bitmap had the incorrect size, you didn’t notice because it was bigger than necessary.

    It’s still nice to fix these things. Thanks for pointing this out!

Leave a Reply

Your email address will not be published. Required fields are marked *