locked
enum values RRS feed

  • Question

  • i'm struggling with enums

    Private Enum sizeMode
        AutoSize = 2
        CenterImage = 3
        Normal = 0
        StretchImage = 1
        Zoom = 4
    End Enum

    here i'm trying to cast a string to a pictureboxsizemode:

    PictureBox1.SizeMode = DirectCast(DirectCast(fields(4), sizeMode), PictureBoxSizeMode)

    what am i doing wrong?

    Saturday, May 23, 2009 7:47 PM

Answers

  • You can't cast string to sizeMode because obviously they are two different types. What you can do is call Enum.Parse:

    PictureBox1.SizeMode = DirectCast([Enum].Parse(GetType(sizeMode), fields(4)), PictureBoxSizeMode)
    • Proposed as answer by Calle Mellergardh Sunday, May 24, 2009 10:12 PM
    • Marked as answer by .paul. _ Monday, May 25, 2009 2:35 AM
    Saturday, May 23, 2009 8:46 PM

All replies

  • You can't cast string to sizeMode because obviously they are two different types. What you can do is call Enum.Parse:

    PictureBox1.SizeMode = DirectCast([Enum].Parse(GetType(sizeMode), fields(4)), PictureBoxSizeMode)
    • Proposed as answer by Calle Mellergardh Sunday, May 24, 2009 10:12 PM
    • Marked as answer by .paul. _ Monday, May 25, 2009 2:35 AM
    Saturday, May 23, 2009 8:46 PM
  • thanks. i found the answer shortly after i posted. thanks for answering though.
    Saturday, May 23, 2009 8:49 PM