作为对象传递时获取控件的ID [英] Get ID of a control when passed as an object

查看:64
本文介绍了作为对象传递时获取控件的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试获取对象的ID.该对象可以是任何控件,例如单选按钮,复选框等...

使用Object.GetType()我所能获得的只是类型,但是我想要ID.该怎么办呢?

是否可以从GUID或哈希码获取控件名称?

从哪里Object.GetHashCode()获取整数值?我的意思是从哪个哈希表获取哈希码?谢谢.

Hi, I am trying to get the ID of an object. The object could be any control like radio-button, check-box etc...

Using Object.GetType() all i could get is the type, but i want the id. How can this be done?

Is it possible to get the control name from GUID or Hashcode?

And from where is Object.GetHashCode() getting the integer value? i mean from which hash-table is it getting it hash-code from? Thanks.

推荐答案

GetHashCode不会从表中返回值.它是可以与哈希表结合使用的值.它的来源取决于对象如何实现它.从默认实现中返回的内容不能保证是有用的,甚至在不同版本的.Net Framework之间也不相同.在此处详细了解.

要获取存储在对象中的控件的ID,请将其强制转换为Control,然后获取ID,它是Control类的属性.
GetHashCode does not return a value from a table. It is a value that can be used in combination with a hash table. Where it comes from depends on how the object implements it. What is returned from the default implementation is not guaranteed to be useful, or even be the same between different versions of the .Net Framework. Read more about that here.

To get the ID of a control stored in an Object, cast it to a Control then get the ID, which is a property of the Control class.


您需要将对象强制转换为控制.从控件继承的单选框和复选框之类的控件包含ID属性.

所以

You need to cast the object as a control. Controls such as radios and checkboxes inherit from Control and Control contains the ID property.

so

<pre><br />
//obj being the control you are trying to get the id for<br />
string strObjId = ((control)obj).id;<br />
</pre>


这篇关于作为对象传递时获取控件的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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