Home » VB.Net

Multiline Labels?

Hello All,
I've been trying to make multiline labels.
That's not possible through code?
That dissapoints me.


8 Answers Found


Answer 1

Hey the two ways that i know work and seem to be a bit more simple:


1(via code). just use lableName.Text = "this is first line\nthis is second line";



2(in the properties box). in Visual Studios click on the little arrow next to the Text property, then hit enter and it returns a new line, this only works when you have clicked the arrow the and a white box pops up otherwise it reads the enter as accept.


Hope this helps!


Answer 2

Unlike a TextBox, to make a Label display a multiline string you do not have to change anything... all you need to do is make sure that you’ve got new line characters in you string which could be as simple as:

        'The more VB style way
        Label1.Text = "Hello" + vbCrLf + "How are you?"
        'The works in almost any (.NET) language way
        Label1.Text = "Hello" + Environment.NewLine + "How are you?"


Answer 3


Here is another suggestion on how to achieve multiline labels.  Instead of sprinkling the text with vbCrLf characters, I found that if I set the label's MaximumSize property to the size of the label, the text will line-wrap within the label.  The AutoSize property must also be set to True.  I found that it is easier than playing with where to insert the vbCrLf characters.  Best of luck.


Answer 4


your soulution is the best one.


Answer 5

Yes, thank you.  It is the best.


Answer 6

If your problem is solved, you should click the "Mark as Answer" button on the response that helped you.  When other programmers are looking for a solution they'll know to click on your thread.


Answer 7

Just to throw in a solution that I did that uses multiline labels

I wanted to create a replacement for MessageBox.Show for errors that had extra features such as "save to file"

In VS 2005 (VB.NET) I created a new dialog form

I added a single label and I added/replaced the actions in the TableLayoutPanel

To make the label act like messagebox text and the form grow like messagebox I did the following

label properties
autosize = true
maximumsize = some reasonable size

The result is the label will grow in height AND it will word wrap based on maximum width

Then for the form, on form_load I put logic to calculate the new height and width and did a size

For the width I used some logic on found on the web (I'm not sure this is the best way but it seemed to make sense) - for the height I simply added the height of the label to the dialog height

Here is some psudeo code...


textFont As Font = lblMessage.Font

'Specify a fixed width, but let the height be "unlimited"

Dim layoutSize As SizeF = New SizeF(lblMessage.Width, 5000.0F)

Dim g As Graphics = Graphics.FromHwnd(lblMessage.Handle)

Dim stringSize As SizeF = g.MeasureString(Text, textFont, layoutSize)



(layoutSize.Width + iSomeAdditionalSpace) > iCurrentDialogWidth Then

    newwidth = layoutSize.Width +

Me.PictureBox1.Width + iSomeAdditionalSpace


newheight = Me.Height + lblMessage.Height

.Size = New Size(newwidth, newheight)


Answer 8

Thanks, GrandpaB. 

This may be an old post, but it was helpful.

Search for  Multiline Labels?


I have TFS 2008. I applied a label to a file, but cannot see this label after I clecked OK. I can only see Name, Pending change, User, Latest. Maybe something is wrong in my setup ? If labels are not displayed, what the sence to have them at all ?





A few additional labeling options might be nice.  1) An option to enforce a labeling standard - perhaps via a drop down list of label types and regex expressions.  2) An quick view of the most recent labels at that level.  3) Some form of auto label based on the type of label selected and the last label of the same type - perhaps based on some number (changeset or version increment) or date. 


I've tried this on 2 TFS installs. Whenever I disable the Label Sources flag for a build, the build fails on the Associate Changesets and Work Items task with this message Error: Cannot find the current label 


Anybody else having this issue?


I have a complex source control issue  Let me build up the context a bit here...

We have a hypothetical version control source tree like this:



Main\Project 1\Source

Main\Project 2\Source




We have 4 seperate build definitions:

Project1 Build, Project2 Build, Common1 Build, Common2 Build.

Each build labels the corresponding source trees with the build number, etc...

The Common code and Projects are developed by seperate teams.  QA will pick up a specific builds of Common and "certify" them as a build they want a team to develop against.  Common is under constant flux and the tip should now be referenced for development against.

A developers workspace looks like this:


$TeamProject\Main\Project 1\Source   -> C:\Sandbox\Main\Project 1\Source

$TeamProject\Main\Project 2\Source   -> C:\Sandbox\Main\Project 2\Source

$TeamProject\Common\CoreLibrary1\Source   -> C:\Sandbox\Common\CoreLibrary1\Source

$TeamProject\Common\CoreLibrary2\Source   -> C:\Sandbox\Common\CoreLibrary2\Source

A developer wants to get the Tip of Project 1 & Project 2, but wants to pull CoreLibrary1 from a specific label and CoreLibrary2 with a different label.  While a develop can do this manually in Team Explorer by right clicking on "CoreLibrary1" and choosing "Get Specific Version" and using the correct label.  Then do the same for "CoreLibrary2" using a different label.

Team explorer's workspace mapping won't allow the developer to specify a label for a specific mapping in the workspace


$TeamProject\Main\Project 1\Source   -> C:\Sandbox\Main\Project 1\Source (Use Tip)

$TeamProject\Main\Project 2\Source   -> C:\Sandbox\Main\Project 2\Source (Use Tip)

$TeamProject\Common\CoreLibrary1\Source   -> C:\Sandbox\Common\CoreLibrary1\Source (Use Label X)

$TeamProject\Common\CoreLibrary2\Source   -> C:\Sandbox\Common\CoreLibrary2\Source (Use Label Y)

The example above is not supported by the "edit workspace" dialog

because of this it would be nice to be able to "combine labels" into a new label that the developer can use for his entire workspace mapping, ie to create a new label "Label Z" which combines Label X and Label Y.

Now the developer can setup the workspace mapping in the original illustration and right click on the root of the team project and choose, "Get Specific Version" and choose "Label Z"

Our real world scenario is much more complex than this (using 20-30 workspace mappings to different source tree areas), but this desciption illustrates the point. 

So the ending question is: How can I create "Label Z"?  I think i can do this by lableing CoreLibrary1 with "Label Z" and then with the Find Label Dialog, choosing "Add" and selecting the items from "Label Y" and Adding items from another label to the existing label.

Again in the real world scenario, we are taliing about massive source trees, it would be easier to be able to use the tf command or find some utility which will allow me to more easily manage labels than Team explorer. 

It would be nice if this could be automated with a Console application that I could provide a file similar to:

Label Z

Label X

Label Y

which could call tf to create Label Z with Label X and Y..  I could write this, I just wanted to be clear on the syntax of calling TF...







Is it possible to display or hide a label based on the text rendered in it?
I have a label that will display the value of a control on the previous page. If the value rendered is "0" then I want to hide the label or hide the label and one more label associated with it. (or if the value is more than "0" make it visible)

Any suggestions would be great.



Last week, Sipla explained how to add a Custom Label line to a labelstyle line in a rangebarchart.  This was implemented with the following code:

Sub finalizeChart(ByVal chartname As Chart)
        chartname.ChartAreas("ChartArea1").AxisX.TitleFont = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)
        chartname.ChartAreas("ChartArea1").AxisY.TitleFont = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)

        indx = 0

        While indx < UnitNames.Count
            chartname.Series("Series1").Points(UnitNamePoint(indx)).AxisLabel = UnitNames(indx)
            indx = indx + 1
        End While

        Dim minFrom As String = minFromDate
        Dim maxThru As String = maxThruDate
        If Not minFrom = "9999-99-99" Then
            chartname.ChartAreas("ChartArea1").AxisY.Minimum = CDate(minFromDate).ToOADate()
        End If
        chartname.ChartAreas("ChartArea1").AxisY.IsMarginVisible = False
        chartname.ChartAreas("ChartArea1").AxisY.IntervalType = DateTimeIntervalType.Months
        chartname.ChartAreas("ChartArea1").AxisY.Interval = 1
        chartname.ChartAreas("ChartArea1").AxisY.LabelStyle.Format = "MMM"

End Sub
Private Sub chtStandardSchedule_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles chtStandardSchedule.Customize
    chtStandardSchedule.ChartAreas("ChartArea1").AxisY.CustomLabels.Add(1, DateTimeIntervalType.Years, "yyyy", 1, LabelMarkStyle.SideMark)
End Sub

Note that the leftmost margin is set by the line: chartname.ChartAreas("ChartArea1").AxisY.Minimum = CDate(minFromDate).ToOADate().  If the minFromDate is at or near January first, the year line, set by the customize subroutine aligns the months and years closely.  But, if the minFromDate is later, say February or beyond, the years start with the month, and end with the same month in the following year.  In other words, the year line does not end on December 31.

Currently look: (Feb Mar......Dec Jan Feb) and underneath each Feb is a tick with the year in between.                                                                       

Desired look:(Feb Mar......Dec Jan Feb) with a tick under the leftmost month (Feb), then under each Dec or Jan.

The various parameters of the CustomLabel don't allow from and to position with the parameters shown above. 

Is there a way to synchronize the start and end of given years with the months they represent?



how to disabled the word label in my aspx page if my query is null... i dont like to show the word label in my aspx page.

im using c# .net


I am getting blank labels after selecting a label option.  Steps below:

CRM 4.0, MS Word 2010.

1. Go to Contacts >> Active Contacts

2. Select a list of contacts and do a mail merge (click on the the mail merge ribbon/icon)

3. Click Open when asked by MS Word

4.  Enable Editing/Enable Content

5.  Click Add-Ins >> CRM

6. The recipients list displays.  I clicked OK

7.  At this point, the Label Option window displays, whereby I selected the desired address label. (i.e. format)

8.  When I do that, the labels are coming up blank/empty.

NOTE:  if I don't select any label option, and just hit Cancel, the merged fields are appearing fine.   However, that would mean, I would have to print one address label per page, so if I have 50 address labels, that would mean 50 pages! :(

Any ideas/suggestions??  THanks much!


OnPaint override - buttons and labels are blank rectangles - label Timer not refreshing

Problem 1

I have a C# program where I override the OnPaint to draw a Sudoku Puzzle.  I have several buttons and a label (displaying a Timer), (added using the Controls.Add).  All worked fine, then at some point in building the application, the buttons and label, were replaced by blank, white rectangles at startup.  Unfortunately, I didn't address the problem then, so I have no idea what caused the problem. 

If I move the window slightly, all of the blank, white rectangles are replaced by the buttons and label, as they should be, (other than the time updating on the label). 

If I minimize the window instead of moving it, then restore it, the blank, white rectangles are replaced by blank, black rectangles, (other than the time updating on the label).  Again, if I move the window slightly, all of the blank, black rectangles are replaced by the buttons and label, as they should be, (other than the time updating on the label). 

The buttons all function properly, even though they appear as blank, white (or black) rectangles.

I haven't included the code, as it is almost 2600 lines of code, but if you need certain pieces to look at, please let me know what to post, and I will do so.

Problem 2 (this may be related to Problem 1)

The label displays a running Timer.  The label’s text doesn't change unless I refresh the window, (minimize and restore).  (The Timer is running, but the time in the label only changes when I refresh the window.)

privatevoid InitializeButtonPuzzleTimerStart()


PuzzleTimer = newTimer();

PuzzleTimer.Interval = 1000;


PuzzleTimer.Tick += newEventHandler(Timer_Tick);

InitialTimerTime = newDateTime();

InitialTimerTime = DateTime.Now;

InitialTimerHour = DateTime.Now.Hour;

InitialTimerMin = DateTime.Now.Minute;

InitialTimerSec = DateTime.Now.Second;

-- other code --

labelPuzzleTimer.Text = GetTime();

PuzzleTimer.Enabled = true;



publicvoid Timer_Tick(object sender, EventArgs eArgs)


if (sender == PuzzleTimer)


labelPuzzleTimer.Text = GetTime();



publicstring GetTime()


TimeInString = "Elapsed Time: ";

TimeSpan TimeDiff = newTimeSpan();

TimeDiff = DateTime.Now.Subtract(InitialTimerTime);

hour = TimeDiff.Hours;

min = TimeDiff.Minutes;

sec = TimeDiff.Seconds;

TimeInString += (hour < 10) ? "0" + hour.ToString() : hour.ToString();

TimeInString += ":" + ((min < 10) ? "0" + min.ToString() : min.ToString());

TimeInString += ":" + ((sec < 10) ? "0" + sec.ToString() : sec.ToString());


return TimeInString;


If I use

protectedvirtualvoid OnPaint(PaintEventArgs pea)

the buttons and label appears, with the running time refreshing properly, but nothing else in my OnPaint draws to the form.

If I use

protectedoverridevoid OnPaint(PaintEventArgs pea)

everything in the OnPaint draws correctly, except the buttons and label, (they appear as in Problem 1).

Is there anything else you need to help me with these problems?  Thank you in advance.


New to Chart Controls.  Can anyone tell me how to add a hyperlink to an EXISTING x-axis label on a column chart control?  Is this possible?  I can't find a label property to do it.  I have 2 series, each has x-axis value set to office name and label property IsValueShownAsLabel = True in series properties window at design time.  I don't want to use custom labels but if I have to, could someone also please tell me how to set the hyperlink property for those instead?  Thanks!


I'm having a problem binding the item selected from a ListView to a multiline TextBox. this is the scenario of my application: I have a Sql Server database with several tables. In one table I have created Projects and in another one People that are in projects. I have created a foreign key in my database to bind this two tables. Now, i have put my projects in a ListView and I want to select one and in the TextBox to appear the people in that project (only their names) each on a line. 

Any idea how can I do that?

Thank you!


how can i create an if statement that is the textbox contains more than one line then do this; else do this

this is what i want ti to look like


If textbox2.text = has more than one line of text thenelseendif


how can i make an if statement the "if textbox2.text has only one line of text then..."

Hi everyone,

I have an infopath form with a multiline textbox and when i enter 3 big paragraphs and submit, only around 30 to 40 words are shown in the sharepoint view. But if i open the submitted form it shows complete text. when i use that entry to send email, it is again clipped. What do i do?

Please help me out.





I need to have a column header on 2 lines in the WPF DataGrid...
How can I do that?



If I have a couple of buttons and the output of these buttons is displayed in a double lined textbox. The output is always diplayed in the top line. How can I make sure that the input is displayed in the bottom line?

Thankts in advance,



Ok one of the forum members helped me by writing this code below but it only works when their is one line of text in textbox4. if their are two lines it doesn't work. I was wondering if you guys can find the problem. i tried switching the lines between >1 or = 1 or > -1. But that doesn't work.

Dim NoMatches AsNew List(Of String)
  Dim Found AsBooleanDim TextboxLine AsStringDim Separator AsChar = "/"c
  ForEach Value AsStringIn TextBox1.Lines
   Found = FalseFor t AsInteger = 0 To TextBox4.Lines.Length - 1
    TextboxLine = TextBox4.Lines(t)
    If TextboxLine.ToLower.Contains(Value.ToLower) ThenIf TextboxLine.IndexOf(Separator) > -1 ThenDim Email AsString = TextboxLine.Split(NewChar() {Separator})(0).Trim(NewChar() {"("c, ")"c})
      Dim ProduktKey AsString = TextboxLine.Split(NewChar() {Separator})(1)
      Found = TrueEndIfExitForEndIfNextIf Found = FalseThen
  TextBox3.Lines = NoMatches.ToArray
Thank You


I have a form that contains a multiline textbox and other single line textboxes all contained in a table structure.

Its a browser enabled form that emails its content (via "Send active view of the form") when submitted.

When testing the email submission, we noticed that in Outlook 2003 the vertical scrollbars in the multiline textbox appear. However, in Outlook 2007 the scrollbars do not appear and hence part of text is not shown.


Is there any way to overcome this? Is this a known issue with outlook 2007 & InfoPath?




Hi All,

      I have a Excel Data Source which has 4 columns "FullName", "EmpID ", "JoinLocation","Division"

      Source would return around 40 to 50 row, in that there will be only value for each columns rest all  is NULL , for example "FullName"  may have value on 12 th row, "EmpID "  may have value on 20 th row as like the below result set. 

FullName                  Division    EmpID    JoinLocation

NULL                        NULL        NULL    NULL
NULL                        NULL        NULL    NULL
NULL                        NULL        NULL    NULL
Manivannan Durai     NULL        NULL    NULL
NULL                        NULL        NULL    NULL
NULL                        NULL        NULL    NULL
NULL                        NULL        NULL    NULL
NULL                        NULL        NULL    NULL
NULL                        NULL        80002  NULL
NULL                        NULL        NULL    NULL
NULL                        NULL        NULL    NULL
NULL                        SothDiv    NULL    NULL
NULL                        NULL        NULL    NULL
NULL                        NULL        NULL    Bangalore


   From this i have to create single result set which is having the values as follows.


FullName                  Division    EmpID    JoinLocation


Manivannan Durai     SothDiv    80002      Bangalore


     So i have used Script Component (Transformation)  with the following code, but i couldn't create the output.  Help me out to achieve this  using Script Component  or any other suitable methods.

Thanks for reading this post...

' Microsoft SQL Server Integration Services Script Component' Write scripts using Microsoft Visual Basic 2008.' ScriptMain is the entry point class of the script.Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> _
<CLSCompliant(False)> _
PublicClass ScriptMain
  Inherits UserComponent
  Public FName AsStringPublic Div AsStringPublic loc AsStringPublic ID AsStringPublicOverridesSub PreExecute()
    '' Add your code here for preprocessing or remove if not needed'EndSubPublicOverridesSub PostExecute()
    '' Add your code here for postprocessing or remove if not needed' You can set read/write variables here, for example:' Me.Variables.MyIntVar = 100'EndSubPublicOverridesSub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    '' Add your code here'If Row.F4_IsNull = FalseThen FName = Row.F4
    If Row.F5_IsNull = FalseThen Div = Row.F5
    If Row.F6_IsNull = FalseThen loc = Row.F6
    If Row.F10_IsNull = FalseThen ID = Row.F10

  EndSubPublicOverridesSub CreateNewOutputRows()
    With Output0Buffer
      .Name = FName
      .Division = Div
      .Location = loc
      .EmpId = ID





Now i want to mark them but deawing a line like underscore or a table so each row will seperate by a line like:


label1                   |                   label30


Something like that but with lines like create a table or something.




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure