C# :: Get Name from control

Last post 08-24-2004 13:15 by ukiller. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-24-2004 7:26

    C# :: Get Name from control

    I create new textbox controls with my application and when i click on such control i would like to know the name of the control.

    I know how i get all the names of the controls with a loop.
    But i want only know the name off the control i clicked.

    The code to generate the control:

    nieuweTextBox.Name = "nieuweTextBox_" + aantal;
    nieuweTextBox.Text = nieuweTextBox.Name.ToString();
    nieuweTextBox.Left = e.X - this.Left;
    nieuweTextBox.Top = e.Y - this.Top-15;
    nieuweTextBox.Click += new System.EventHandler(this.test);

    Controls.Add(nieuweTextBox);
    aantal = aantal + 1;

    The function test is at this time:
    private void test(object sender, System.EventArgs e)
    {
    Type typeOfObject = sender.GetType();
    foreach (Control tempCtrl in Controls)
    {
    //this.Controls.Remove(tempCtrl);
    MessageBox.Show(tempCtrl.Name.ToString(),"Informatie");
    }
    }

    But i want only the name of the control i clicked....

    thanx
  • 08-24-2004 13:15 In reply to

    Re: C# :: Get Name from control

    you should get the information you are looking for by inspecting the sender object in your code. Yor are looping through the global Controls collection that doesn't know anything about the selected control.
Page 1 of 1 (2 items)