Sender, how to code it as one line code.

B

Boki

Hi All,

We can assign multi object ( ex: textbox )'s double click point to a
same function. ex:


private void all_boki_textbox_point_here_DoubleClick(object sender,
EventArgs e)
{
...
...

}

If I have many objects, they are totally doing the same thing, ex:
copy textboxN's text to a specify textbox.

my code become:
private void all_boki_textbox_point_here_DoubleClick(object sender,
EventArgs e)
{
if (sender == textbox1)
final_text_box.text=textbox1.text;

if (sender == textbox2)
final_text_box.text=textbox2.text;

....
}

How to write code as only one line ?

Thanks!



Best regards,
Boki.
 
J

Jesse Houwing

* Boki wrote, On 9-7-2007 11:12:
Hi All,

We can assign multi object ( ex: textbox )'s double click point to a
same function. ex:


private void all_boki_textbox_point_here_DoubleClick(object sender,
EventArgs e)
{
..
..

}

If I have many objects, they are totally doing the same thing, ex:
copy textboxN's text to a specify textbox.

my code become:
private void all_boki_textbox_point_here_DoubleClick(object sender,
EventArgs e)
{
if (sender == textbox1)
final_text_box.text=textbox1.text;

if (sender == textbox2)
final_text_box.text=textbox2.text;

...
}

How to write code as only one line ?

Thanks!



Best regards,
Boki.


TextBox tb = sender as TextBox;
if (tb != null)
{
finalTextBox.Text = tb.Text;
}

would do the trick.

Jesse
 
B

boki.digital

* Boki wrote, On 9-7-2007 11:12:








TextBox tb = sender as TextBox;
if (tb != null)
{
finalTextBox.Text = tb.Text;

}

would do the trick.

Jesse

Great, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top