|
-
Jul 8th, 2008, 10:25 AM
#1
Thread Starter
New Member
[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.
-
Jul 8th, 2008, 10:31 AM
#2
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 
-
Jul 8th, 2008, 12:40 PM
#3
Fanatic Member
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!
-
Jul 8th, 2008, 12:46 PM
#4
Addicted Member
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?
-
Jul 8th, 2008, 12:49 PM
#5
Re: [2008] Label / Autosize property
Do you mean DataGrid(02/03) = DataGridView(05/08) ?
__________________
Rate the posts that helped you 
-
Jul 8th, 2008, 12:57 PM
#6
Addicted Member
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.
-
Jul 9th, 2008, 04:20 AM
#7
Thread Starter
New Member
Re: [2008] Label / Autosize property
how do you create your own label? Is this really advanced stuff?
-
Jul 9th, 2008, 04:44 AM
#8
Re: [2008] Label / Autosize property
 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:
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
-
Jul 9th, 2008, 05:48 AM
#9
Thread Starter
New Member
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?
-
Jan 22nd, 2015, 01:29 PM
#10
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?
-
Jan 22nd, 2015, 03:14 PM
#11
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.
-
Jan 22nd, 2015, 03:55 PM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|