开发者

How can I automatically update an int value in a label?

So here's my situation, I have a form (Stats), with a bunch of labels containing integer values related to the players attributes IE: strength, agility, dexterity, etc. The thing I'm trying to figure out how to do is to have these values updated and passed to the corresponding forms automatically each time the player's stats change.

Say for example the players strength is 10, and then he equips an item that increases his strength by 5, how would I get the value in the corresponding attribute label to update automatically and equal 15?

T开发者_高级运维hank you for any help!


First, make your data class that contains the strength, agility and such implement INotifyPropertyChanged (or use a PostSharp for this)

Then databind the label to this:

control.Data1Label.DataBindings.Add("Text", fighter, "Strength");


MVC architecture. make the view (your form) to observe the Modele (your data class). When a modification happen in the data. The modele fire an event (or you could implement the observer pattern on your own) to make the the view update it data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜