I have a class UserPane l: Panel. I do so.
private bool AutoSize_ = true;
public bool AutoSize
{
get
{
return AutoSize_;
}
set
{
AutoSize_ = value;
}
}
But when I change Autosize_ still returns are always true. How to make that value correctly transmitted.
The Panel class already have a property AutoSize.
You define a new Property with the same name. Check your warnings, you must have the following :
warning CS0114: 'UserPanel.AutoSize' hides inherited member 'System.Windows.Forms.Panel.AutoSize'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
When you are calling the AutoSize property of UserPanel, you are in fact calling the property of the superclass Panel. So your field AutoSize_ will never get changed.
Act accordingly to the warning :
public class UserPanel : Panel
{
private bool AutoSize_ = true;
public override bool AutoSize
{
get
{
return AutoSize_;
}
set
{
AutoSize_ = value;
}
}
}
On a side note, why do you want to change the already working AutoSize functionnality? Are you sure this is what you need?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With