79330675

Date: 2025-01-05 12:10:44
Score: 1
Natty:
Report link

You’re getting this error because System.Drawing.Color is not an enum. Use Color.FromName to convert the color name into a Color object. Here’s the fixed code

using System.Drawing;
using System.IO;

string[] TournamentData = File.ReadAllLines(@"C:\\TournamentData.txt");
string colorName = TournamentData[2].Trim();
button.BackColor = Color.FromName(colorName);

Explanation: Color.FromName: Converts the color name (e.g., "Red") into a Color object. .Trim(): Removes extra spaces or newline characters.

Make sure the color names in the file are valid, like "Red" or "Blue."

If this solves your issue, please upvote the answer. Thank you!

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (0.5): upvote
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Dinesh Choudhary