In my winforms application I have some code that needs to be executed after the text is changed. On the label I have a textchanged event with the following code:
string value = lblText.Text;
int labelWidth = lblText.Width;
int controlWidth = groupPanel1.Width;
int difference = controlWidth - labelWidth;
lblText.Left = difference / 2;
When I set a breakpoint at string value = lblText.Text;
I see the correct value. But the width property returns the width of the previous value of the text property.
For example:
The first time: text = "hello world!" width: 0
Second time: text = "h" width: 60
Third time: text = "hi" width: 13
How is that possible?