Run-Time Defined objects and event handling...

[b][red]This message was edited by Shug at 2004-3-23 10:36:51[/red][/b][hr]
[b][red]This message was edited by Shug at 2004-3-23 10:34:30[/red][/b][hr]
I'm trying to write a generic event handler for -all- (well, the ones that I specify anyways...) my text fields' Enter/Leave focus event.

If I create this handler:

[code][blue]static void[/blue] txtbox_Enter ([blue]object[/blue] sender, SystemEvent.Args e)
{
[blue]if[/blue] (sender.Equals(System.Windows.Forms.Textbox))
[green]//change the sending textbox's background color[/green]
}[/code]
... how can I access the run-time defined properties/methods (so I don't have to code a specific method for each textbox)? Specifically, the event-generating-control's Textbox.Background property.

Is there a way to cast the sender object into a System.Windows.Forms.Textbox, so I can access the background property?

Thanks, Hugh




Comments

  • : [b][red]This message was edited by Shug at 2004-3-23 10:36:51[/red][/b][hr]
    : [b][red]This message was edited by Shug at 2004-3-23 10:34:30[/red][/b][hr]
    : I'm trying to write a generic event handler for -all- (well, the ones that I specify anyways...) my text fields' Enter/Leave focus event.
    :
    : If I create this handler:
    :
    : [code][blue]static void[/blue] txtbox_Enter ([blue]object[/blue] sender, SystemEvent.Args e)
    : {
    : [blue]if[/blue] (sender.Equals(System.Windows.Forms.Textbox))
    : [green]//change the sending textbox's background color[/green]
    : }[/code]
    : ... how can I access the run-time defined properties/methods (so I don't have to code a specific method for each textbox)? Specifically, the event-generating-control's Textbox.Background property.
    :
    : Is there a way to cast the sender object into a System.Windows.Forms.Textbox, so I can access the background property?
    :
    : Thanks, Hugh
    :
    :
    :
    :
    :

    [code]private void txt_Enter(object sender, EventArgs e)
    {
    if(object is TextBox)
    ((TextBox)sender).BackColor = Color.Red;
    }
    }
    [/code]

    Charlie
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion