Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable setting of a property in winforms designer

I'm using Yet Another TabControl in my project - it's custom, open sourced TabControl with support for designer. After solving some of its problems, I've stumbled upon a problem I have no clue how to solve.

When I run my application, YATabControl would select the same tab I selected in designer - which is not exactly what I want (I'd rather start with first tab) and I can't move through the tabs while application is running, because it tries to save property "SelectedIndex" on every change of tab.

It is set on designers ~onclick using:

RaiseComponentChanging( TypeDescriptor.GetProperties( Control )[ "SelectedIndex" ] );  
RaiseComponentChanged( TypeDescriptor.GetProperties( Control )[ "SelectedIndex" ], oi, i );(old index, index).

I'm thinking - is there a way to disable designer from setting runtime value of property?

like image 808
mrówa Avatar asked Oct 24 '25 17:10

mrówa


2 Answers

I looked at the source code (didn't download it), but it looks like you have to tell the SelectedIndex property to not serialize itself:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual int SelectedIndex {
  get {
    return yaSelectedIndex;
  }
  set {...}
}
like image 171
LarsTech Avatar answered Oct 26 '25 08:10

LarsTech


[Browseable(false)] is the way to go :)

like image 36
Florian Avatar answered Oct 26 '25 07:10

Florian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!