I'm building a custom messagebox. All works fine, but I thing not....

I want my messagebox auto resizes in height when adding more text than expected in design mode. In design mode a draw a label of 4 lines of text, but when I call the new messagebox with much more text, it disappears. The call of the messagebox may have 10 lines of text, without any "environment.newline". So, in that case the messagebox AND the label have to resize in height (not in width!). Optionaly the OK/Cancel button have to replace, to position themselfs again under the resized label.

Is this possible

Re: Windows Forms General Label auto height


Yep you can do it.

After you assign the text, run this code;

Dim LaySize As New SizeF(lblMessage.Width, 5000)

Dim G As Graphics = Graphics.FromHwnd(lblMessage.Handle)

Dim Sz As SizeF = G.MeasureString(lblMessage.Text, lblMessage.Font, LaySize)

lblMessage.Height = (Sz.Height + 3)

Based on the new size of the label, you can alter your forms size and button locations accordingly.

Re: Windows Forms General Label auto height


Check this thread.