Z
Zoury
Hi everyone! :O)
I need a C# equivalent for the VB's CallByName() function.. I've looked at
the Delegate information in the MSDN and I'm familiar with Reflection (i've
listed the members of an assembly). I'm quite new to all these topics though
and I couldn't figured out the best way to do the following :
/***/
private void Form1_Load(object sender, System.EventArgs e)
{
Hashtable htProperties = new Hashtable();
htProperties["Text"] = "Salut!";
htProperties["BackColor"] = Color.DarkBlue;
htProperties["ForeColor"] = Color.Blue;
htProperties["Font"] = new Font("Comic Sans MS", 10, FontStyle.Bold);
ApplyCustomProperties(htProperties, label1);
}
private void ApplyCustomProperties(
System.Collections.Hashtable ht,
System.Windows.Forms.Label lbl)
{
foreach(DictionaryEntry entry in ht)
{
switch(entry.Key.ToString())
{
case "Text":
lbl.Text = entry.Value.ToString();
break;
case "BackColor":
lbl.BackColor = (Color)entry.Value;
break;
case "ForeColor":
lbl.ForeColor = (Color)entry.Value;
break;
case "Font":
lbl.Font = (Font)entry.Value;
break;
default: break;
}
}
}
/***/
I'll actually need to implement a similar "system" for a couple of homemade
control. We'll pass the hashtable or whatever else data structure to our
control in order to set it's properties. As I said I've take a look at the
delegates but it seems to be way to much overhead for my needs.
thanks in advance for the input :O)
--
Best Regards
Yanick Lefebvre
ps : I've read the following thread :
http://groups.google.com/groups?&threadm=OJTIoYp1BHA.2536@tkmsftngp05
I actually tried to understand and apply the solution proposed by Eric
Gunnerson without any success...
I need a C# equivalent for the VB's CallByName() function.. I've looked at
the Delegate information in the MSDN and I'm familiar with Reflection (i've
listed the members of an assembly). I'm quite new to all these topics though
and I couldn't figured out the best way to do the following :
/***/
private void Form1_Load(object sender, System.EventArgs e)
{
Hashtable htProperties = new Hashtable();
htProperties["Text"] = "Salut!";
htProperties["BackColor"] = Color.DarkBlue;
htProperties["ForeColor"] = Color.Blue;
htProperties["Font"] = new Font("Comic Sans MS", 10, FontStyle.Bold);
ApplyCustomProperties(htProperties, label1);
}
private void ApplyCustomProperties(
System.Collections.Hashtable ht,
System.Windows.Forms.Label lbl)
{
foreach(DictionaryEntry entry in ht)
{
switch(entry.Key.ToString())
{
case "Text":
lbl.Text = entry.Value.ToString();
break;
case "BackColor":
lbl.BackColor = (Color)entry.Value;
break;
case "ForeColor":
lbl.ForeColor = (Color)entry.Value;
break;
case "Font":
lbl.Font = (Font)entry.Value;
break;
default: break;
}
}
}
/***/
I'll actually need to implement a similar "system" for a couple of homemade
control. We'll pass the hashtable or whatever else data structure to our
control in order to set it's properties. As I said I've take a look at the
delegates but it seems to be way to much overhead for my needs.
thanks in advance for the input :O)
--
Best Regards
Yanick Lefebvre
ps : I've read the following thread :
http://groups.google.com/groups?&threadm=OJTIoYp1BHA.2536@tkmsftngp05
I actually tried to understand and apply the solution proposed by Eric
Gunnerson without any success...