facebooktwittermenuarrow-up

GemBox Support Forum

Add textbox into another textbox

So, I’m tryint to acchieve something like in the image
2022-05-04 10_52_41-Window

My idea was to use two textboxes and add the smaller white one to the bigger, blue one. Sadly I havent found a way to add my inline textbox via Blocks.Add() or Inline.Add() so far.
Any recommendations/advice?

Hi Daniel,

You could do that by adding the inner TextBox to Paragraph which you could then add to the outer TextBox.Blocks.

However, note that this will only work for the output PDF files, Word files don’t support having TextBox elements inside the TextBox element.

Anyway, try this:

var document = new DocumentModel();
document.DefaultParagraphFormat.SpaceAfter = 0;

var section = new Section(document);
document.Sections.Add(section);

var outerTextBox = new TextBox(document,
    Layout.Inline(new Size(400, 120)), ShapeType.RoundedRectangle);
section.Blocks.Add(new Paragraph(document, outerTextBox));

outerTextBox.AdjustValues.Add("adj", 4600);
outerTextBox.Fill.SetSolid(Color.Blue);

outerTextBox.Blocks.Add(
    new Paragraph(document,
        new Run(document, "IT Service")
        { CharacterFormat = { FontColor = Color.White } }));

outerTextBox.Blocks.Add(
    new Paragraph(document,
        new Run(document, "3.1.VDI")
        { CharacterFormat = { FontColor = Color.White, Size = 18, Bold = true } }));

var innerTextBox = new TextBox(document,
    Layout.Inline(new Size(382, 65)), ShapeType.RoundedRectangle);
outerTextBox.Blocks.Add(new Paragraph(document, innerTextBox));

innerTextBox.AdjustValues.Add("adj", 4600);

var innerParagraph = new Paragraph(document);
innerTextBox.Blocks.Add(innerParagraph);

innerParagraph.ParagraphFormat.Tabs.Add(new TabStop(80, TabStopAlignment.Right));
innerParagraph.ParagraphFormat.Tabs.Add(new TabStop(90, TabStopAlignment.Left));
innerParagraph.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.Tab));
innerParagraph.Inlines.Add(new Run(document, "Description:") { CharacterFormat = { Bold = true } });
innerParagraph.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.Tab));
innerParagraph.Inlines.Add(new Run(document, "End User Computing"));

innerParagraph = new Paragraph(document);
innerTextBox.Blocks.Add(innerParagraph);

innerParagraph.ParagraphFormat.Tabs.Add(new TabStop(80, TabStopAlignment.Right));
innerParagraph.ParagraphFormat.Tabs.Add(new TabStop(90, TabStopAlignment.Left));
innerParagraph.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.Tab));
innerParagraph.Inlines.Add(new Run(document, "Recovery Order:") { CharacterFormat = { Bold = true } });
innerParagraph.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.Tab));
innerParagraph.Inlines.Add(new Run(document, "25"));

innerParagraph = new Paragraph(document);
innerTextBox.Blocks.Add(innerParagraph);

innerParagraph.ParagraphFormat.Tabs.Add(new TabStop(80, TabStopAlignment.Right));
innerParagraph.ParagraphFormat.Tabs.Add(new TabStop(90, TabStopAlignment.Left));
innerParagraph.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.Tab));
innerParagraph.Inlines.Add(new Run(document, "Mtpd:") { CharacterFormat = { Bold = true } });
innerParagraph.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.Tab));
innerParagraph.Inlines.Add(new Run(document, "02:00 hours"));

document.Save("output.pdf");

Here is the resulting PDF:

I hope this helps.

Regards,
Mario

Perfect, exactly what I needed, since it will be PDF anyway.

Can I use AdjustValues to increase my textbox height afterwards?

No, for that you can use the TextBox.Layout.Size property.

1 Like