473,671 Members | 2,163 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 1254
Hi

Try this
string ColorName = ...;

System.Drawing. Color MyColor;

if (ColorName[0]=='#')
MyColor = System.Drawing. Color.FromArgb( int.Parse(Color Name.Substring( 1,2),System.Glo balization.Numb erStyles.HexNum ber),nt.Parse(C olorName.Substr ing(3,2),System .Globalization. NumberStyles.He xNumber),int.Pa rse(ColorName.S ubstring(5,2),S ystem.Globaliza tion.NumberStyl es.HexNumber));
else
MyColor = System.Drawing. Color.FromName( ColorName);
"Mevar81" <to*****@hotmai l.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.Subs tring
(1,2),System.Gl obalization.Num berStyles.HexNu mber),nt.Pars
e(ColorName.Sub string
(3,2),System.Gl obalization.Num berStyles.HexNu mber),int.Par
se(ColorName.Su bstring
(5,2),System.Gl obalization.Num berStyles.HexNu mber));else
MyColor = System.Drawing. Color.FromName (ColorName);"Mevar81" <to*****@hotmai l.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
1700
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
1903
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
3578
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, reads it field by field, encodes
16
16390
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
4008
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 that I implement it as a struct rather than a class which I did and all worked OK. The simplest declaration for the struct is:
4
5061
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 deleted, however it must be initialized by a function during run-time to contain so many users which each contain so many directories of which each contain so many files. I've completed the program and have it running flawlessly without implementing...
31
6153
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 make a method to print out its data in a similar format. So, I did this: public struct MyStruct { public override string ToString() {
74
15971
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 creation of this implicit default constructor, to force the creation of a struct via my constructor only? Zytan
7
18439
by: MJ_India | last post by:
Style 1: struct my_struct { ... }; typedef my_struct my_struct_t; Style 2: typedef struct my_struct {
0
8474
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8669
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.