Dynamically increase Label size [AutoSize]

Recently I had to work on a windows form where the Labels are added dynamically onto the form. Some of you may think that setting AutoSize to true would fix the problem but it works only when you already have added that Label control onto the form, not when you are adding it dynamically.

Despair not, there’s still a solution. Just create a label and set it’s text first then call this function:

If you do some testing it may not work on Compact Framework. Here’s how to get around that issue again.

comments powered by Disqus