在运行时更改单选按钮的文本 [英] Changing the text of a Radio Button at run time

查看:80
本文介绍了在运行时更改单选按钮的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用表单设计器创建的表单(C ++/CLI .NET)上有一个单选按钮.

但是在某些情况下,我想更改其关联的文本.

只需将新字符串分配给-> Text属性不会产生任何影响.

我尝试了诸如Invalidate和Update之类的操作来重新生成控件.他们没有帮助.

I have a radio button on a form (C++/CLI .NET) created using the form designer.

But in certain circumstance I want to change its associated text.

Simply assigning the new string to the ->Text property has no impact.

I tried things like Invalidate and Update to regenerate the control. They did not help.

推荐答案

请提供代码,想知道为什么它不起作用;
尝试点击事件..
Please provide the code, wondering why its not working;
try it on click event..
private void button1_Click(object sender, EventArgs e)
        {
       
            radioButton1.Text = textBox1.Text;
        }


不需要无效.您认为属性Text的作者是白痴吗?当然,将新值(不同于上一个值)分配给该属性时,单选按钮的客户区无效.这是通过属性设置器完成的.

我不知道您观察到将新字符串分配给-> Text属性没有影响"的确切原因,但是我敢肯定这一定是您的错误.可能有不同的原因:新值并不是真正的新值,实际上未调用赋值运算符,UI由于某种原因而挂起,等等.您可以在Debugger下轻松运行代码以查看发生了什么.实际上,您应该在提出类似问题之前先做一下,很可能是-而不是提出问题. :-)

为了成功,你会做功课吗?

—SA
No invalidation is needed. Do you think the author of the property Text is an idiot? Of course the client area of a radio button is invalidated when a new value (different from the previous one) is assigned to the property; this is done via the property setter.

I don''t know the exact reason of you observation that "assigning the new string to the ->Text property has no impact", but I''m certain it must be your mistake. There can be different reasons: the new value is not really new, the assignment operator is actually not called, UI is hanging by some reason, etc. You can easily run your code under Debugger to see what''s going on. Actually, you should do it before asking a question like that, very likely — instead of asking the question. :-)

Do you homework in order to succeed.

—SA


这篇关于在运行时更改单选按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆