Results 1 to 2 of 2

Thread: Unexpected Label Width Size

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    Unexpected Label Width Size

    Background Info: I'm building an app which I keep expanding. The point of it all, is to view pictures stored into Album directories. It's for a Music Collection, whereas:
    • File Structure: D:\Music\Artist\Album
    • Each album folder has a collection of 6 pictures.
    • The app will have 7 tab pages within a tab control
    • The First Tab will view all images of an individual album
    • Each of the six remaining tabs will display the specific image from each Album folder, each with a label on top, and on bottom (Artist Label / PictureBox / Album Label)
    • With 1,200 CDs, that's 1,200 images per tab. There will be some dynamic movement going on (print first, move to the right, print the second...until I have to go to the next line, so on and so forth...)
    • With 7,200 images to load, I will have to figure something out so it doesn't crash on me, I don't think I'm there yet.


    Anyways, I'm currently working with one tab where I'm displaying a PictureBox (pboIMG) at a specific starting location. Using the X,Y Positions of the PictureBox and the Height/Width, I'm setting a starting location of a label, above it. I'll be doing the same thing below it, as well. For now, the top label is called lblArtist, which I'm having trouble with. When I draw a control at Design time, the height is ALWAYS 25, it just does it by default, based on the font name and font size, I believe. I always have AutoSize set to True. However, at runtime, when drawing a label box, both height and width are off.

    Here's my code:

    Code:
    Dim lblArtist As New Label
    With lblArtist
        .Text = "asdfasdfasdfsfadf"
        .Font = New Font("Segoe UI", 14.25, FontStyle.Regular)
        .AutoSize = True
        .Location = New Point(pboIMG.Location.X + ((pboIMG.Width - lblArtist.Width) / 2), (pboIMG.Location.Y - 5 - lblArtist.Height))
    End With
    I have isolated the issue, but I do not know how to fix it. Basically, it looks like the AutoSize is not working correctly on the lblArtist Label Control, for neither Height or Width.

    To test:
    • I Copied/Pasted existing labels from my first tab, which were also set to AutoSize = True.
    • First Label Control: The Text "Cover.jpg" produced a size of (Height) 92, (Width) 25.
    • Copied Label Control: The Text "asdfasdfasdfsfadf" produced a size of 158, (Width) 25.
    • In fact, every time I use the ToolBox to draw a new label, the Height defaults to 25.
    • When drawing a label box at runtime with the text "asdfasdfasdfsfadf", it produces the size of (Width) 100, (Width) 23, when it should be 158, 25 as in my Copy/Paste test.
    • For my pasted label control, I manually set the width to 100, which forced the text to cut off. This was expected.
    • For the controls drawn, AutoSize = True in Properties. For the runtime control, .AutoSize = True is used in an Width/End With statement, as you can see in my code.
    • I have checked every other input I will be using in the formula to calculate the starting position, they are all correct.



    Question: Why is the size of the label control which is drawn at runtime, not working as expected and how can I fix this? Is there another property that I need to set that I'm missing?

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Unexpected Label Width Size

    the default size of a label comes because of it's text "Label 1" (or what ever number it happens to be). It also doesn't get drawn until it is actually placed on a container, which is going to affect the size. So if you are checking size immediately after the code above, it may be inaccurate. You'll need to .Add it to a .Controls collection first, then check it's .Size property to see what the rendered size ended up being.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

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