Hi,
Is it possible to wrap the text in the ToolStripLabel I'm trying to create a help tool like the help screen that opens up in Office products (ie:Word). I'm populating a ToolStrip with ToolStripLables and would like the text to wrap.
Thank you.
Jon

ToolStripLabel
Jakein2006
I'm coding in VB.NET so I use environment.newline and it is working. However, I need a scrollbar and there is no scrollbar so now I'm playing with the TableLayoutPanel which does have a scrollbar. However, I can't get the scrollbar to showup after i resume layout for the TableLayoutPanel. Need help either with:
a) use the ToolStrip and find a way to add a scrollbar or
b)use the TableLayoutPanel and figure out how to get the scrollbar to show up.
Any help you could offer for either direction (option a or b) would be GREAT!
Here is my code for both(the code for the TableLayoutPanel is commented out):
#Region "Declares"
Private modobjarrSITHData() As dtcChangeRequest.SITHData
#End Region
Private Sub frmHelp_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
' get data
modobjarrSITHData = DataConnections.SITH.RetrieveTopLevel()
TableLayoutPanel1.SuspendLayout()
' add items to toolstripDim i As Integer
Dim locintRecordCount As Integer = -1
Dim locobjSITHItems(modobjarrSITHData.GetUpperBound(0)) As ToolStripLabel
Dim locobjSITHItems2(modobjarrSITHData.GetUpperBound(0)) As LinkLabel
Dim locstrSITHDescription As String = ""
Dim locintDescriptionLength As Int32 = -1 For i = 0 To modobjarrSITHData.GetUpperBound(0)
locintRecordCount += 1
New ToolStripLabellocintDescriptionLength += modobjarrSITHData(locintRecordCount).SITHDescription.Length
locobjSITHItems(locintRecordCount) =
'locobjSITHItems2(locintRecordCount) = New LinkLabel
locobjSITHItems(locintRecordCount).Image = Bitmap.FromFile("C:\\Fantastapottumus\icons\help.gif")
'locobjSITHItems2(locintRecordCount).ImageAlign = ContentAlignment.TopLeft
locobjSITHItems(locintRecordCount).IsLink = True
locobjSITHItems(locintRecordCount).DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
locobjSITHItems(locintRecordCount).Name = modobjarrSITHData(locintRecordCount).SITHID
'locobjSITHItems2(locintRecordCount).Name = modobjarrSITHData(locintRecordCount).SITHID If locintDescriptionLength > 45 Then
locstrSITHDescription = modobjarrSITHData(locintRecordCount).SITHDescription.Substring(0, 45) + Environment.NewLine + modobjarrSITHData(locintRecordCount).SITHDescription.Substring(46, locintDescriptionLength - 45)
locobjSITHItems(locintRecordCount).Text = locstrSITHDescription
Else
locobjSITHItems(locintRecordCount).Text = modobjarrSITHData(locintRecordCount).SITHDescription
End If 'locobjSITHItems2(locintRecordCount).Text = modobjarrSITHData(locintRecordCount).SITHDescription 'locobjSITHItems2(locintRecordCount).Anchor = AnchorStyles.Left Or AnchorStyles.Right 'locobjSITHItems2(locintRecordCount).AutoSize = True 'locobjSITHItems2(locintRecordCount).BorderStyle = BorderStyle.FixedSingle
locintDescriptionLength = -1
'FlowLayoutPanel1.Controls.Add(locobjSITHItems2(locintRecordCount)) 'TableLayoutPanel1.RowStyles.Add(New RowStyle(SizeType.AutoSize)) 'TableLayoutPanel1.Controls.Add(locobjSITHItems2(locintRecordCount), 0, locintRecordCount) NextTableLayoutPanel1.ResumeLayout()
ToolStrip1.Items.AddRange(locobjSITHItems) Catch ex As Exception End Try End Substellag
nrf
IamHuM
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.toolStripLabel1.AutoSize = false;
this.toolStripLabel1.Size = new Size(60, 44);
this.toolStripLabel1.Text = "Try a\r\nlong line";
}
}
Note that you can't insert "\r\n" in the designer, you'll have to do it at run-time.
SPWilkinson
With the ToolStripLabel I can use the DisplayStyle property to lign up an icon next to the text.
I have tried using a panel, the TableLayoutPanel, and I have set the AutoScroll property to True and for some reason the scrollbar is not there. The code is above.
Paulson Abraham
I took care of the loading issue by suspending layout, creating the link labels, then resuming the layout - very speedy now.
I did try the panel approach but it piled all of my LinlLabel controls on top of each other.
The TableLayoutPanel is derived from the Panel control. It allows me to create a unique row for each LinkLabel I create. However, the scrollbar is not showing up. If I resize the form after runtime sometimes the scrollbar shows up...
fa6ma
I have the solution. Here are the property settings for the TableLayoutPanel:
Anchor = Left
AutoSize = False
AutoScroll = False
AutoScrollMinSize=0,1000 ' the height will need to be adjusted based on how many records you think you will be returning.
I edited the Columns collection - changed to AutoSize.
Same for Rows collection.
In the code behind I changed the AutoSize of each LinkLabel to False and then adjusted the height according to the length of the text. I also entered in a fixed width. The vertical scrollbar now appears due to the AutoScrollMinSize. I'll probably end up dynamically setting the AutoScrollMinSize based on how many records I return. (ie: 100 records returned multiply 1000*2 and so on).
I also wanted to add an Icon (which is why I started with ToolStrip because of the nice DisplayStyle property). Easy fix, just add another column to TableLayoutPanel and set the image property to the bitmap.