Prev: creating activeX on VB.NET 2008
Next: .NET 3.5 - System.Reflection.Assembly does not release object (DLL) after use
From: Rick on 31 Mar 2010 19:07 I am dynamically creating a label control of width=100 and adding text (sTextVar) to it dynamically whose string length is unknown: Dim myLabel As Label = New Label() myLabel.Width = 100 myLabel.Text = sTextVar Me.Controls.Add(myLabel) 1. How do I set myLabel so the font size of sTextVar is shrunk to smaller size? 2. How do I set myLabel so sTextVar is displayed in multiple lines?
From: Cor Ligthert[MVP] on 1 Apr 2010 03:50 Hi Rick, Try to avoid the prefixes with data types, it looks so awful from the previous millennium when we did not have intelligence \\\ Dim myLabel As New Label With {.Size = New Size(70, 100), .Location = New Point(10, 10), _ .Font = New Font("Arial Narrow", 8.25, FontStyle.Regular), _ .Text = MyText} Me.Controls.Add(myLabel) /// Success Cor "Rick" <Rick(a)discussions.microsoft.com> wrote in message news:AB013A8B-CAB1-4020-9C14-1F19573220E7(a)microsoft.com... > I am dynamically creating a label control of width=100 and adding text > (sTextVar) to it dynamically whose string length is unknown: > > Dim myLabel As Label = New Label() > myLabel.Width = 100 > myLabel.Text = sTextVar > Me.Controls.Add(myLabel) > > 1. How do I set myLabel so the font size of sTextVar is shrunk to smaller > size? > 2. How do I set myLabel so sTextVar is displayed in multiple lines?
From: Rick on 2 Apr 2010 16:07 Cor, This is not what I am looking for. I need to be able to adjust the font size dynamically based on the text size of the label. With your example; if I set the size to 100 and the label contains a text of 500 (for example) then I will be able to see only what is going to fir with the textbox of sized 100. BTW, I like your suggestion for not using the prefixes with data type. thanks "Cor Ligthert[MVP]" wrote: > Hi Rick, > > Try to avoid the prefixes with data types, it looks so awful from the > previous millennium when we did not have intelligence > > \\\ > Dim myLabel As New Label With {.Size = New Size(70, 100), .Location = New > Point(10, 10), _ > .Font = New Font("Arial Narrow", 8.25, > FontStyle.Regular), _ > .Text = MyText} > Me.Controls.Add(myLabel) > /// > > Success > > Cor > > "Rick" <Rick(a)discussions.microsoft.com> wrote in message > news:AB013A8B-CAB1-4020-9C14-1F19573220E7(a)microsoft.com... > > I am dynamically creating a label control of width=100 and adding text > > (sTextVar) to it dynamically whose string length is unknown: > > > > Dim myLabel As Label = New Label() > > myLabel.Width = 100 > > myLabel.Text = sTextVar > > Me.Controls.Add(myLabel) > > > > 1. How do I set myLabel so the font size of sTextVar is shrunk to smaller > > size? > > 2. How do I set myLabel so sTextVar is displayed in multiple lines? > > . >
From: Phill W. on 6 Apr 2010 08:07
On 01/04/2010 00:07, Rick wrote: > I am dynamically creating a label control of width=100 and adding text > (sTextVar) to it dynamically whose string length is unknown: > > Dim myLabel As Label = New Label() > myLabel.Width = 100 > myLabel.Text = sTextVar > Me.Controls.Add(myLabel) > > 1. How do I set myLabel so the font size of sTextVar is shrunk to smaller > size? > 2. How do I set myLabel so sTextVar is displayed in multiple lines? Extend the Label class (i.e. create one that inherits from Label) and use that in place of the standard one. Override the Text property and, in the set routine, you can do whatever adjustments you like to the Font, etc. Class CustomLabel Inherits Label Public Sub New() Me.AutoSize = False Me.Size = New Size( 100, 24 ) End Sub Public Overrides Property Text() As String Get Return MyBase.Text End Get Set(ByVal value As String) MyBase.Text = value ' Adjust other properties as required End Set End Property End Class Labels implicitly display on multiple lines - you just have to worry about making your control tall enough for the text to fit. There are plenty of ways to kludge the sizing, to do the job "properly", read up on Graphics.MeasureString(). HTH, Phill W. |