Hi,
I’m actually having a problem with textbox shape. I set both shape and textbox wrap mode properties to “none” and still wrap text if it exceeds shape width.
Here’s the code:
Private Function GetNewShape(ByVal builder As DocumentBuilder, ByVal shapeType As ShapeType,
ByVal left As Double, ByVal top As Double,
ByVal width As Double, ByVal height As Double) As Shape
Dim shape = New Shape(builder.Document, shapeType)
shape.AllowOverlap = True
shape.Left = left
shape.Top = top
shape.Width = width
shape.Height = height
shape.Stroked = False
shape.WrapType = WrapType.None
Select Case shapeType
Case Drawing.ShapeType.TextBox
shape.TextBox.FitShapeToText = False
shape.TextBox.InternalMarginBottom = 1
shape.TextBox.InternalMarginTop = 1
shape.TextBox.InternalMarginRight = 1
shape.TextBox.InternalMarginLeft = 1
shape.TextBox.TextBoxWrapMode = TextBoxWrapMode.None
Case Drawing.ShapeType.Image
End Select
Return shape
End Function
Is this a known issue or am I missing something?!
Thanks to you!
JSr
Hi
Thanks for your request. Unfortunately, I cannot reproduce the problem on my side. I used the following code for testing:
Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
Dim shape = New Shape(builder.Document, ShapeType.TextBox)
shape.AllowOverlap = True
shape.Width = 10
shape.Height = 10
shape.Stroked = False
shape.TextBox.FitShapeToText = True
shape.Textbox.TextBoxWrapMode = TextBoxWrapMode.None
shape.TextBox.InternalMarginBottom = 1
shape.TextBox.InternalMarginTop = 1
shape.TextBox.InternalMarginRight = 1
shape.TextBox.InternalMarginLeft = 1
builder.InsertNode(shape)
' insert some text into tetbox.
Dim par As New Paragraph(doc)
shape.AppendChild(par)
builder.MoveTo(par)
builder.Write("This text will not wrap inside textbox")
doc.Save("C:\Temp\out.doc")
I used the latest version of Aspose.Words for testing. You can download it from here:
https://releases.aspose.com/words/net
Best regards,
Hi,
Thank you for your reply. The text doesn’t wrap because you set “FitShapeToText” to true so the textbox grows for the text to fit in it.
I would like to draw a textbox, lets say it has 50 as width value. I’d like the textbox to display as much chars as it can in its width, and doesn’t display the exceeding ones instead of wrapping.
I hope you understand my point! Sorry for my english too…
Thanks,
Jsr
Hi
Thank you for additional information. In this case, you should fix both width and height of text box. If height of text box will enough only for one line of text, the rest text will not be visible. But in this case, if height of text box is bier, text will wrap. I am afraid you cannot prevent this.
Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
Dim shape = New Shape(builder.Document, ShapeType.TextBox)
shape.AllowOverlap = True
' Set fixed sizr of textbox
shape.Width = 100
shape.Height = 14
shape.Stroked = False
shape.TextBox.InternalMarginBottom = 1
shape.TextBox.InternalMarginTop = 1
shape.TextBox.InternalMarginRight = 1
shape.TextBox.InternalMarginLeft = 1
builder.InsertNode(shape)
' insert some text into tetbox.
Dim par As New Paragraph(doc)
shape.AppendChild(par)
builder.MoveTo(par)
builder.Write("This text will not wrap inside textbox")
doc.Save("C:\Temp\out.doc")
best regards,
Hi,
Thanks once again, nice support!
That workaround works great here for the moment.
Have a nice day,
Jsr