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.
Printable View
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.
Will this help?
Code:For Each labForm As Control In Me.Controls
If labForm.GetType.Name = "Label" Then CType(labForm, Label).Autosize= true
Next
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
On a related note, do you guys know what happened to the grid in 2003? Or is there something new/similar?
Do you mean DataGrid(02/03) = DataGridView(05/08) ?
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.
how do you create your own label? Is this really advanced stuff?:eek:
Hi,Quote:
Originally Posted by dsmith00
Here's a way how to create a label dynamic:
vb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim label As New Windows.Forms.Label label.Location = New Point(50, 50) label.Size = New Size(50, 20) label.BackColor = Color.Azure Controls.Add(label) End Sub
Wkr,
sparrow1
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?
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?
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:
that is overriding the default AutoSize value.Code:ToolboxItem("System.Windows.Forms.Design.AutoSizeToolboxItem, ...
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.
After your form is designed, you can delete it from 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
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.