473,511 Members | 10,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dinamicallt creation of a struct

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
Nov 15 '05 #1
2 1247
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.H exNumber),nt.Parse(ColorName.Substring(3,2),System .Globalization.NumberStyles.HexNumber),int.Parse(C olorName.Substring(5,2),System.Globalization.Numbe rStyles.HexNumber));
else
MyColor = System.Drawing.Color.FromName(ColorName);
"Mevar81" <to*****@hotmail.com> wrote in message news:02****************************@phx.gbl...
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

Nov 15 '05 #2
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);"Mevar81" <to*****@hotmail.com> wrote in message

news:02****************************@phx.gbl...
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

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
1691
by: Sam Sungshik Kong | last post by:
Hello! I want to know when I have to use "new" for struct creation. //---------Case 1 struct S { public int I; }
3
1896
by: Karl M | last post by:
Hi everyone, I just notice some strange behaviors on the MS C++ compiler regarding struct default constructor, see the example bellow: struct MyStruct { int a; }; class MyClass { public:
12
3559
by: Sadeq | last post by:
Is there a way to read a struct field by field? I want to write a rather general function, like: public string EncodeStruct (struct strct) { .... } which accepts a general struct type,...
16
16364
by: Gerrit | last post by:
Hello, Is it possible to sort an array with a struct in it? example: I have a struct: public struct mp3file { public int tracknr;
37
3978
by: JohnGoogle | last post by:
Hi, Newbie question... After a recent article in VSJ I had a go at implementing a Fraction class to aid my understanding of operator overloading. After a previous message someone suggested...
4
5053
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
31
6120
by: Zytan | last post by:
Everything (er, every class) in C# has ToString() which is conveniently automatically invoked when using it in Debug.WriteLine() or in a string concatenation, etc. I made a struct, and I want to...
74
15870
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
7
18428
by: MJ_India | last post by:
Style 1: struct my_struct { ... }; typedef my_struct my_struct_t; Style 2: typedef struct my_struct {
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.