![](/img/trans.png)
[英]WinForms UserControl Designer for Control[] Property
[英]Format property for custom control in winforms designer
UInt64Converter類提供了您所需的大多數內容,因為它支持從十六進制格式進行的轉換。 所需ConvertTo
就是重寫ConvertTo
to方法以顯示為十六進制。
public class UInt64HexConverter : UInt64Converter
{
private static Type typeUInt64 = typeof(UInt64);
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
{
throw new ArgumentNullException("destinationType");
}
if (((destinationType == typeof(string)) && (value != null)) && typeUInt64.IsInstanceOfType(value))
{
UInt64 val = (UInt64)value;
return "0x" + val.ToString("X");
}
if (destinationType.IsPrimitive)
{
return Convert.ChangeType(value, destinationType, culture);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
用法示例:
class BitControl : Control
{
[TypeConverter(typeof(UInt64HexConverter))]
public ulong Mask { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.