Simple way to bind two different properties together?
In my application I always want hscrollbar.LargeChange
to equal panel.Width
. Currently I set hscrollbar.LargeChange
to panel.Width
in resizing events, painting events, et cetera. I do not know much about binding so I'm wondering if it is possible to do this.
Sorry if this is a simple question but when I trie开发者_JS百科d googling binding and c# I got a lot of complicated information about other platforms.
Actually, there is a way to bind the LargeChange property of the HScrollBar to the Width property of the panel, but I think I've just discovered a bug in .NET 4 with regards to this as it works if I target .NET 3.5.
Basically, you need to manually create a Binding object and assign it to the HScrollBar's DataBindings collection, like so:
hScrollBar1.DataBindings.Add(new Binding("LargeChange", panel1, "Size.Width", true, DataSourceUpdateMode.OnPropertyChanged));
Again, this doesn't work in .NET 4, but it does in .NET 3.5. I'll probably submit a bug report.
Cheers
Yes, the way you are doing it, in the panel.Resize event is the only way to do it in windows forms.
精彩评论