Hi gix1,
If you don't like the property to be edited, you can hide the property by the Browsable attribute.
[Browsable(false)]
public string P1
{
get { return p1; }
set { p1 = value; }
}
If you need the property to be displayed on the Properties Windows, but hide its value(show blank on the value box), you can use a custom TypeConverter, for example:
public class mycontrol : UserControl
{
private string p1 = "aaaaa";
//[Browsable(false)]
[TypeConverter(typeof(P1TypeConverter))]
public string P1
{
get { return p1; }
set { p1 = value; }
}
}
public class P1TypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
return true;
else
return false;
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
else
return false;
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return value.ToString();
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return "";
}
}
Please try my suggest and let me know if it helps.
Best Regards,
Zhi-Xin
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Send us any feedback you have about the help from MSFT at
fbmsdn@microsoft.com.