c# - Binding in winform like in WPF -
i want bind winform's form's width property text on label label's text gets updated every mouse movement made. achieved updating when element on form clicked not continious updating(like if change text in resize handler). how thing?
you can bind width property doing this:
label1.databindings.add(new binding("text", this, "width"));
the problem there form isn't notifying framework property has changed. easiest best bet meat , potatoes way:
protected override void onresize(eventargs e) { base.onresize(e); label1.text = this.width.tostring(); }
edit: okay, if want use data binding, here way works (but reaching around head scratch ear):
add object data source form , set datasource type "system.windows.forms.form".
next, add code:
public form2() { initializecomponent(); this.formbindingsource.datasource = this; binding binding = new binding("text", this.formbindingsource, "size", true); binding.format += new converteventhandler(binding_format); label1.databindings.add(binding); } void binding_format(object sender, converteventargs e) { size size = (size)e.value; e.value = size.width.tostring(); }
so said, it's complete overkill, works.
Comments
Post a Comment