I'm trying to create a custom messagebox. The MessageBox's form obviously contains a label.
Just like the Windows MessageBox:
The text in the label could be of any length.
The label is of fixed width.
The label can have varying height.
The third point is the problem right now, I don't know how to make it have a varying height, I'd like to make it size itself accordingly with the text in there.
Here is what I tried:
VB Code:
Dim _tmp_Graphics As System.Drawing.Graphics Dim [hl=yellow]_tmp_SizeF As New System.Drawing.SizeF(_tmp_Graphics.MeasureString(_lbl.Text, _lbl.Font))[/hl] Dim _lblSize_Height As Single Dim _lblSize_Width As Single _lblSize_Height = _tmp_SizeF.Height _lblSize_Width = _tmp_SizeF.Width .Size = New System.Drawing.Size(_lblSize_Width, _lblSize_Height)
_lbl is a System.Windows.Forms.Label.
This errors out with a
on the yellow, highlighted line above.NullReferenceException
Object reference not set to an instance of an object.
I can see that _tmp_Graphics = Nothing, but System.Drawing.Graphic's New() is private.
Really not sure if this is even the right approach.
Guidance, please.![]()




Reply With Quote