یه حلقه Foreach میخوام که دونه به دونه کنترلها بسته به نوعشون رو توش مقداردهی کنم.
خواهش میکنم از دوستان که استادن تو این زمینه که کمکم کنند.
مثه این نمونه :
foreach (var ctl in pnl.Controls)
{
// for every control type
// come up with a way to Draw its
// contents
if (ctl is Label)
{
var lbl = (Label)ctl;
gr.DrawString(
lbl.Text,
lbl.Font,
new SolidBrush(lbl.ForeColor),
lbl.Location.X, // simple based on the position in the panel
lbl.Location.Y);
}
if (ctl is PictureBox)
{
var pic = (PictureBox)ctl;
gr.DrawImageUnscaledAndClipped(
pic.Image,
new Rectangle(
pic.Location.X,
pic.Location.Y,
pic.Width,
pic.Height));
}
if (ctl is TextBox)
{
var txt = (TextBox)ctl;
gr.DrawString(
txt.Text,
txt.Font,
new SolidBrush(txt.ForeColor),
txt.Location.X, // simple based on the position in the panel
txt.Location.Y);
}
}