0

I have winform project in C#. I add Krypton Toolkits to my project for visual quality. I added TextBox control from Krypton Toolkit. But unfortunately I have a problem with textbox events. I couldn't get Textbox name.

These are my codes :

private void TextBox_Click(object sender, EventArgs e)
    {
        string tbName = string.Empty;
        // I tried this but it gives me t as null
        //KryptonTextBox t=sender as KryptonTextBox;
        // tbName= t.Name;

        // It gives me textbox name is empty ""
        TextBox tb = sender as TextBox;
        tbName = tb.Name;
        tbName = tb.AccessibleName; // give me null
        tbName = tb.Tag.ToString(); // give me null

        // I tried @ Jimi's advice
        Control c = sender as Control;
        tbName = c.Name; // it gives me empty
        tbName = c.AccessibleName; // give me null
        tbName = c.Tag.ToString();// give me null

        // it react like it isn't KryptonToolbox, so passed the if condition.
        if (c is KryptonTextBox)
        {
            tbName = (c as KryptonTextBox).Name; 
        }

        if (c is TextBox)
        {
            tbName = (c as TextBox).Name; // gives me empty.

        }
    }

enter image description here

enter image description here

Edit: The way @dr.null has suggested is worked. I added

kryptonTextBox1.Textbox.Name="kryptonTextbox1";
Gokhan
  • 453
  • 4
  • 10
  • 1
    Have you tried to cast to `Control` instead? It's the class that defines the `Name` Property. `KryptonTextBox` probably wraps a TextBox, but doesn't directly derive from it. – Jimi May 19 '22 at 21:31
  • @Jimi thanx for attention. If I'm not mistaken, I did what you said. I edited post.But it not worked. – Gokhan May 20 '22 at 03:42
  • All right. Anyway, if you set a breakpoint in that event handler and you inspect `sender`, what does the debugger tell you? Is it `null` or some other Type? Did you actually check? – Jimi May 20 '22 at 04:12
  • @Jimi I edited the post. I added a pic while debugging. – Gokhan May 20 '22 at 04:30
  • 1
    According to the image, you are setting the properties of the `kryptonTextBox1` object not the internal `TextBox`'s. In the ctor, set `kryptonTextBox1.TextBox.Name = "someName";` and the same for other properties of the **TextBox**. Now, cast the `sender` in the `Click` event as `TextBox` and you'll get what you set. `(sender as TextBox).Name` -> `someName`. – dr.null May 20 '22 at 11:21

0 Answers0