Dinamicallt creation of a struct

  • Thread starter Thread starter Mevar81
  • Start date Start date
M

Mevar81

Anyone know if is it possible to create dinamically a
struct?For example I want to set the color of a button
while at runtime, and to set it's ForeColor property I
need to read a Xml file where I store the property value
of the button.The color is a System.drawing.Color
struct.Anyone know how to create a struct from a string
that rappresent the struct (for example a string like
Color.AliceBlue).Thanks to everybody
 
Hi

Try this


string ColorName = ...;

System.Drawing.Color MyColor;

if (ColorName[0]=='#')
MyColor = System.Drawing.Color.FromArgb(int.Parse(ColorName.Substring(1,2),System.Globalization.NumberStyles.HexNumber),nt.Parse(ColorName.Substring(3,2),System.Globalization.NumberStyles.HexNumber),int.Parse(ColorName.Substring(5,2),System.Globalization.NumberStyles.HexNumber));
else
MyColor = System.Drawing.Color.FromName(ColorName);
 
Thank you.I try what you suggest and everything work.Thak
you again.
-----Original Message-----
Hi

Try this


string ColorName = ...;

System.Drawing.Color MyColor;

if (ColorName[0]=='#')
MyColor = System.Drawing.Color.FromArgb(int.Parse (ColorName.Substring
(1,2),System.Globalization.NumberStyles.HexNumber),nt.Pars
e(ColorName.Substring
(3,2),System.Globalization.NumberStyles.HexNumber),int.Par
se(ColorName.Substring
(5,2),System.Globalization.NumberStyles.HexNumber));
else
MyColor = System.Drawing.Color.FromName (ColorName);
Anyone know if is it possible to create dinamically a
struct?For example I want to set the color of a button
while at runtime, and to set it's ForeColor property I
need to read a Xml file where I store the property value
of the button.The color is a System.drawing.Color
struct.Anyone know how to create a struct from a string
that rappresent the struct (for example a string like
Color.AliceBlue).Thanks to everybody
 
Back
Top