Results 1 to 6 of 6

Thread: Sizing a label properly [Resolved]

Threaded View

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Resolved Sizing a label properly [Resolved]

    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:
    1. Dim _tmp_Graphics As System.Drawing.Graphics
    2.  
    3.  
    4.             Dim [hl=yellow]_tmp_SizeF As New System.Drawing.SizeF(_tmp_Graphics.MeasureString(_lbl.Text, _lbl.Font))[/hl]
    5.  
    6.             Dim _lblSize_Height As Single
    7.             Dim _lblSize_Width As Single
    8.  
    9.             _lblSize_Height = _tmp_SizeF.Height
    10.             _lblSize_Width = _tmp_SizeF.Width
    11.  
    12.             .Size = New System.Drawing.Size(_lblSize_Width, _lblSize_Height)

    _lbl is a System.Windows.Forms.Label.

    This errors out with a

    NullReferenceException
    Object reference not set to an instance of an object.
    on the yellow, highlighted line above.

    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.
    Last edited by mendhak; Sep 30th, 2004 at 04:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width