Converting System.Drawing.Color to Brushes.Color? RRS feed

  • Question

  • User341897124 posted
    I'm trying to get text input from the user and assigning it straight to a brush. So if they entered "Maroon", the variable brTemp of type Brush would be assigned the value Brushes.Maroon Maybe I'm not thinking right, but is there an easy way to do this? I don't think a long case statement would be a very elegant solution. Drawing.Color has FromArgb, FromKnownColor, and FromName methods, but Brushes.Color doesn't seem to have anything like that. I'd even settle for RGB values entered by the user.
    Tuesday, October 19, 2004 2:04 PM

All replies

  • User-1413657921 posted
    When you are typing, say:Brush myBrush = Brushes.SlateBlue; basically all you are getting is a instatiated SolidBrush set to the color Color.SlateBlue. In addition it caches a thread-safe copy of the brush instance, but it doesn't sound like something you'd have any particular use for in your current case. With that in mind, couldn't you just as easily stop using Brushes, and instead just instantiate your brush yourself:Brush myBrush = new SolidBrush(Color.FromName(myColorNameString));That will get you the exact same brush type. HTH -Christian
    Tuesday, October 19, 2004 8:21 PM