Results 1 to 3 of 3

Thread: Multiple Controls using the same event *resolved*

  1. #1

    Thread Starter
    Hyperactive Member Colonel Klink's Avatar
    Join Date
    Aug 2002
    Location
    Gold Coast, Australia
    Posts
    329

    Multiple Controls using the same event *resolved*

    i have this code, when i dynamically create a textbox....

    Code:
    txt.KeyUp += new System.Windows.Forms.KeyEventHandler(txt_KeyUp);
    i have this for a generic event handler (ie multiple texboxes use this event)

    Code:
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    		{
                            TextBox txtbox = (TextBox)sender;
                            try
                            {
    				if(e.KeyValue.ToString() == "13")
                            	{
                                            if (txtbox.Text != "")
                                            {
                            			connection.Sender.PublicMessage(txtbox.Tag.ToString(), txtbox.Text);
                                    		txtbox.Text = "";
                    			}
                                    }
                            }
                            catch( Exception e1 )
                            {
                            	rtfStatusOut.Text = "\n" + e1;
                            }
    		}
    however, when i use it, it doesnt send and clear the textbox, nor does it raise an exception

    any ideas on what it could be?
    Last edited by Colonel Klink; Sep 20th, 2003 at 09:47 AM.

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    Colonel,

    Maybe the System.Windows.Forms.KeyEventHandler is the wrong event try maybe try the KeyPress event?

    Code:
    txt.KeyUp += new System.Windows.Forms.KeyEventHandler(txt_KeyUp);

    Mitchel
    Last edited by toto; Sep 19th, 2003 at 02:21 PM.

  3. #3

    Thread Starter
    Hyperactive Member Colonel Klink's Avatar
    Join Date
    Aug 2002
    Location
    Gold Coast, Australia
    Posts
    329
    got it working... i changed (in the if loop) if(e.KeyCode.ToString() == "Enter") ... and it worked fine
    and also i forgot to add text to the tag on creation so that was another reason
    Our Father, who 0wnz heaven, j00 r0ck!
    May all 0ur base someday be belong to you!
    May j00 0wn earth just like j00 0wn heaven.
    Give us this day our warez, mp3z, and pr0n through a phat pipe.
    And cut us some slack when we act like n00b lamerz, just as we teach n00bz when they act lame on us.
    Please don't give us root access on some poor d00d'z box when we're too pissed off to think about what's right and wrong, and if you could keep the fbi off our backs, we'd appreciate it.
    For j00 0wn r00t on all our b0x3s 4ever and ever, 4m3n.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width