在设计带来新的十进制为什么指定为控件的属性数值(新INT [] {...在code? [英] Why does specifying a numeric value for a control's property in the designer result in new decimal(new int[] {... in the code?

查看:154
本文介绍了在设计带来新的十进制为什么指定为控件的属性数值(新INT [] {...在code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C#.NET WinForm的在VS2005的应用程序,我有一个NumericUpDown控件。在设计师,我的的NumericUpDown的最小属性设置为-65535。

In my C#.Net WinForm app in VS2005, I have a NumericUpDown control. In the designer, I set the Minimum property of the NumericUpDown to -65535.

在窗体的了.Designer.cs code,我希望看到这样的:

In the form's .designer.cs code, I expected to see this:

this.myNumericUpDown.Minimum = -65535;

而是我得到的:

but instead I get:

    this.myNumericUpDown.Minimum = new decimal(new int[] {
    65535,
    0,
    0,
    -2147483648});

我知道这意味着什么,从仰视 INT32 []小数构造,但为什么设计师使用,而不是把我的输入值,甚至使用的 INT32小数构造

I know what this means from looking up the int32[] decimal constructor, but why does the designer use that form instead of putting the value I entered, or even using the int32 decimal constructor?

推荐答案

在理论上的设计人员可以将原创的输入文本。然而,由于可视化设计器也可以修改这些值(即左,上,等),那就序列化过程中调和这对存储控件的值。这是presumably一个原因设计者不存储输入的文本值,而它需要的文字并将其转换为可以被放置于控制值。当它需要序列化,它只是读取控件的属性,并将其写入。将有小点询问小数的细节之前,存储只是为了优化要使用的构造函数。它需要处理小数类型的所有可能值,从而INT []提供往返可靠的存储机械师任何值十进制可以重新present。

In theory the designer could store your original input text. Yet since the visual designer can also modify these values (i.e. Left, Top, etc) it would have to reconcile this storage against the control's values during serialization. This is presumably one reason why the designer does not store the text values entered, rather it takes your text and converts it to a value that can be placed into the control. When it needs to serialize it just reads the control's properties and writes them. There would little point to interrogate the details of the decimal prior to storage just to optimize which constructor to use. It needs to handle all possible values of the decimal type, thus the int[] provides a round-trip reliable storage mechanic for any value a decimal can represent.

顺便说一句,下面简单介绍一下十进制的内部结构:

BTW, the following outlines the internal structure of the decimal:

  • 位是32位有符号整数的四元素的数组。
  • 位[0],位[1],位[2]含有低,的96位整数中间,和高的32位。
  • 位[3]中包含的比例因子和标志,以及由以下部分组成:
    • 在0〜15位,低字,未使用的,必须是零。
    • 第16位到23必须包含0至28之间的指数,这表明10的幂来划分整数。
    • 在24位到30未使用的,必须是零。
    • 在第31位包含符号; 0表示正,1表示阴性。
    • bits is a four-element array of 32-bit signed integers.
    • bits [0], bits [1], and bits [2] contain the low, middle, and high 32 bits of the 96-bit integer number.
    • bits [3] contains the scale factor and sign, and consists of following parts:
      • Bits 0 to 15, the lower word, are unused and must be zero.
      • Bits 16 to 23 must contain an exponent between 0 and 28, which indicates the power of 10 to divide the integer number.
      • Bits 24 to 30 are unused and must be zero.
      • Bit 31 contains the sign; 0 meaning positive, and 1 meaning negative.

      更新:

      你能解释一下......因为可视化设计器也可以修改这些值,......那就要调和这对存储序列化过程中控制的价值观......更详细?

      Would you explain "...since the visual designer can also modify these values, ... it would have to reconcile this storage against the control's values during serialization..." in more detail?

      当然。我只是想解决你的问题为什么设计师使用这种形式的而不是把我的输入值的的字面跨pretation。基本上我想说的是,设计者并没有让你进入-65535的具体文本值的轨道。相反,它转换为与类似decimal.Parse(...)一个小数。然后它把这个小数到控制的值,在这种情况下NumericUpDown.Minimum。后记它通过读取每个属性值序列化,在xxxx.Designer.cs文件中的控制的状态。因此,它不再具有原来的文-65535您输入,但只有产生的十进制值的副本。

      Sure. I was just trying to address the literal interpretation of your question "why does the designer use that form instead of putting the value I entered". Basically all I'm saying is that the designer doesn't keep track of the exact textual value you entered "-65535". Instead, it converts it to a decimal with something like decimal.Parse(...). Then it places this decimal into the control's value, in this case NumericUpDown.Minimum. Afterwords it serializes the state of the control in the xxxx.Designer.cs file by reading each property value. Thus it no longer has a copy of the original text "-65535" you entered, but only the resulting decimal value.

      的部分指的是调和此存储...是简单地指出,这将是困难的不仅跟踪由用户原始文本输入,也检测是否该值已经通过某些其它被改变意味着,原来的文字输入。

      The part referring to "reconcile this storage..." was to simply to point out that it would be difficult to not only track the original text input by a user, but also detect if that value had been changed by some other means that the original text input.

      很抱歉,如果这仍然是令人困惑我在描述它的麻烦。英语是我第5次语言,仅次于C#,C ++,SQL,和JScript所有这些都更加明确的意义比英文:)

      Sorry if that is still confusing I'm having trouble describing it. English is my 5th language, right behind C#, C++, SQL, and JScript all of which are much more explicit in meaning than English :)

      这篇关于在设计带来新的十进制为什么指定为控件的属性数值(新INT [] {...在code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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