我无法获得K k krypton Textbox名称C#

发布于 2025-01-31 03:43:40 字数 1565 浏览 2 评论 0原文

我有C#中的Winform项目。我在我的项目中添加K k k king,以提高视觉质量。我添加了来自K k k的文本框控件。但不幸的是,我对文本框事件有问题。我无法获得文本框名称。

这些是我的代码:

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.

        }
    }

“在此处输入图像描述”

“在此处输入图像描述”

编辑: @null博士建议的方式是有效的。我添加了

kryptonTextBox1.Textbox.Name="kryptonTextbox1";

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";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文