I'm developping a windowsForms app in C#

As i created a lot of labels programmaticaly in the form_Load() ispecify the
following to manage the event in the same way for all of my labels:


So in this sub i wanted to call another form with a specific contructor
which set specific values from with the settings of the caller (obviously a
Label)

My code is the following:
private void _ChangeSettings(object sender, System.EventArgs e)
{
//MessageBox.Show(string.Concat("_changeSettings", sender.GetType(),
"//", sender.ToString() ));
//Load Form1 with the caller
if (sender.GetType().ToString() ==
"System.Windows.Forms.Label".ToString())
{System.Windows.Forms.Label lbl = sender;
Form1 f = new Form1(lbl);
f.Closed += new System.EventHandler(this._ChangeLabelSettings);
f.Show();}
}

when i'm building my solution i have the following error
Cannot implicitly convert type 'object' to 'System.Windows.Forms.Label'

How to convert object to Forms.Label????

Thanks for your help

Re: how to convert object to Forms.Label type ??? by Claes

Claes
Mon Aug 09 03:12:16 CDT 2004

You'll need an explicit cast
Label lbl = (Label) sender;

/claes

"jhs" <jhs@discussions.microsoft.com> wrote in message
news:7E0EBE01-F416-4EF1-A098-BB23ED97DEBB@microsoft.com...
> I'm developping a windowsForms app in C#
>
> As i created a lot of labels programmaticaly in the form_Load() ispecify
the
> following to manage the event in the same way for all of my labels:
>
>
> So in this sub i wanted to call another form with a specific contructor
> which set specific values from with the settings of the caller (obviously
a
> Label)
>
> My code is the following:
> private void _ChangeSettings(object sender, System.EventArgs e)
> {
> //MessageBox.Show(string.Concat("_changeSettings", sender.GetType(),
> "//", sender.ToString() ));
> //Load Form1 with the caller
> if (sender.GetType().ToString() ==
> "System.Windows.Forms.Label".ToString())
> {System.Windows.Forms.Label lbl = sender;
> Form1 f = new Form1(lbl);
> f.Closed += new System.EventHandler(this._ChangeLabelSettings);
> f.Show();}
> }
>
> when i'm building my solution i have the following error
> Cannot implicitly convert type 'object' to 'System.Windows.Forms.Label'
>
> How to convert object to Forms.Label????
>
> Thanks for your help
>