Results 1 to 12 of 12

Thread: [2008] Label / Autosize property

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    3

    [2008] Label / Autosize property

    Is there any way to change the default autosize property on a label in Visual Basic 2008?
    In VB6 the autosize is set as false, and it is very annoying that for each label placed on the form, you have to changet the property.

  2. #2
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [2008] Label / Autosize property

    Will this help?

    Code:
    For Each labForm As Control In Me.Controls
                If labForm.GetType.Name = "Label" Then CType(labForm, Label).Autosize= true
    Next
    __________________
    Rate the posts that helped you

  3. #3
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    Re: [2008] Label / Autosize property

    That would help for the top level controls, but any labels inside other controls would be missed. The easiest way to change the default would be to create your own Label that inherits from the normal one and override (or shadow) the Autosize property. Then use that control instead of the built in Windows one.

    Otherwise, you could do what the post says to do above, but you have to make a recursive function for it:

    Code:
    In the form load:
    ...
    For Each labForm As Control In Me.Controls
        FixAutosize(labForm)
    Next
    ...
    
    Public Sub FixAutosize(ByVal control As Control)
        If labForm.GetType.Name = "Label" Then 
           CType(labForm, Label).Autosize= true
    
        For Each cntl As Control In control.Controls
            FixAutosize(cntl)
        Next
    End Sub
    If your problem is solved, please use the Mark Thread As Resolved under Thread Tools!

    Show Appreciation. Rate Posts!

  4. #4
    Addicted Member sauronsmatrix's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    133

    Re: [2008] Label / Autosize property

    On a related note, do you guys know what happened to the grid in 2003? Or is there something new/similar?

  5. #5
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [2008] Label / Autosize property

    Do you mean DataGrid(02/03) = DataGridView(05/08) ?
    __________________
    Rate the posts that helped you

  6. #6
    Addicted Member sauronsmatrix's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    133

    Re: [2008] Label / Autosize property

    no, not that. It was like a visual grid that appeared on the form, and it made the labels not like camouflaged into the form.

    It's more like a series of dots than a grid.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    3

    Re: [2008] Label / Autosize property

    how do you create your own label? Is this really advanced stuff?

  8. #8
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2008] Label / Autosize property

    Quote Originally Posted by dsmith00
    how do you create your own label? Is this really advanced stuff?
    Hi,

    Here's a way how to create a label dynamic:

    vb.net Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim label As New Windows.Forms.Label
    3.         label.Location = New Point(50, 50)
    4.         label.Size = New Size(50, 20)
    5.         label.BackColor = Color.Azure
    6.         Controls.Add(label)
    7.     End Sub

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    3

    Re: [2008] Label / Autosize property

    i've noticed all these solutions are in the actual coding.

    Is there any way, so that when you are designing a user interface and drawing labels on the form (before you even start coding) that you can have the default value of autosize set as false.

    It is quite tiresome to manually change each one, so that the lables will be laid out the size that you drag them out. I dont want to have to code each of the labels into postion. VB6 you could drag the label out to the size you wished, and therefore appropriately set out the UI. Is the only way to do the same, manually change each autoszie property? or do some codeing to do it at run time?

  10. #10
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,190

    Re: [2008] Label / Autosize property

    Digging up a skeleton here...

    Why is the default for AutoSize on labels still set to True in 2013??? The IDE bolds the value so it thinks False should be the default which is what I would MUCH prefer. The only solution is still making your own control?

  11. #11
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: [2008] Label / Autosize property

    While I typically do not respond to resurrected threads and feel that you should have posted this as a new question, here is a little bit of info and possible help.

    You correctly identified that the AutoSize property has a default value of False. However, it is being changed by the designer code. The Label class is decorated with the attribute:
    Code:
    ToolboxItem("System.Windows.Forms.Design.AutoSizeToolboxItem, ...
    that is overriding the default AutoSize value.

    Here is a little twist on the custom control theme mentioned above that can be added to your Form and can be deleted when you are done. It is an extender component that gets queried when you drop a control on the form. If the component is Enabled (Default) and the control is a Label, it will reset the AutoSize property. Just add this to your project/compile/drag from toolbox to the form.

    Code:
    Public Class KillLabelAutoSize
       Inherits System.ComponentModel.Component
       Implements System.ComponentModel.IExtenderProvider
       Private _Enabled As Boolean = True
       Public Property Enabled As Boolean
          Get
             Return _Enabled
          End Get
          Set(value As Boolean)
             _Enabled = value
          End Set
       End Property
       Public Function CanExtend(extendee As Object) As Boolean Implements System.ComponentModel.IExtenderProvider.CanExtend
          If _Enabled Then
             If TypeOf extendee Is System.Windows.Forms.Label Then
                DirectCast(extendee, System.Windows.Forms.Control).AutoSize = False
             End If
          End If
          Return False
       End Function
    End Class
    After your form is designed, you can delete it from the form.

  12. #12
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,190

    Re: [2008] Label / Autosize property

    Cool. Normally I wouldn't bring back the dead but this was the only thread I found that was exactly what I was after so why duplicate?

    For now I've been getting around this by creating all the labels I'll need and then mass selecting them, which I need to do anyway to change the font and perhaps some other properties.

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